Avoid default arguments in EmbedderTest::OpenDocument().

Default arguments are banned on virtual functions. Remove default
arguments and rename OpenDocument() to OpenDocumentWithOptions(). Add
wrappers for OpenDocumentWithOptions() to call it with sensible options.

Change-Id: I4955d88cf77a7eab1771692ea3d6a18260b52900
Reviewed-on: https://pdfium-review.googlesource.com/21891
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
diff --git a/core/fpdfapi/parser/cpdf_parser_embeddertest.cpp b/core/fpdfapi/parser/cpdf_parser_embeddertest.cpp
index 6aa3e27..4109715 100644
--- a/core/fpdfapi/parser/cpdf_parser_embeddertest.cpp
+++ b/core/fpdfapi/parser/cpdf_parser_embeddertest.cpp
@@ -59,7 +59,7 @@
 }
 
 TEST_F(CPDFParserEmbeddertest, LoadMainCrossRefTable) {
-  EXPECT_TRUE(OpenDocument("feature_linearized_loading.pdf", nullptr, true));
+  EXPECT_TRUE(OpenDocumentLinearized("feature_linearized_loading.pdf"));
   // To check that main cross ref table is loaded correctly,will be enough to
   // check that the second page was correctly loaded. Because it is contains
   // crossrefs for second page.
diff --git a/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp b/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp
index 834ed8c..a1d5fda 100644
--- a/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp
+++ b/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp
@@ -19,7 +19,7 @@
 }
 
 TEST_F(CPDFSecurityHandlerEmbeddertest, UnencryptedWithPassword) {
-  ASSERT_TRUE(OpenDocument("about_blank.pdf", "foobar"));
+  ASSERT_TRUE(OpenDocumentWithPassword("about_blank.pdf", "foobar"));
   EXPECT_EQ(0xFFFFFFFF, FPDF_GetDocPermissions(document()));
 }
 
@@ -28,16 +28,16 @@
 }
 
 TEST_F(CPDFSecurityHandlerEmbeddertest, BadPassword) {
-  EXPECT_FALSE(OpenDocument("encrypted.pdf", "tiger"));
+  EXPECT_FALSE(OpenDocumentWithPassword("encrypted.pdf", "tiger"));
 }
 
 TEST_F(CPDFSecurityHandlerEmbeddertest, UserPassword) {
-  ASSERT_TRUE(OpenDocument("encrypted.pdf", "1234"));
+  ASSERT_TRUE(OpenDocumentWithPassword("encrypted.pdf", "1234"));
   EXPECT_EQ(0xFFFFF2C0, FPDF_GetDocPermissions(document()));
 }
 
 TEST_F(CPDFSecurityHandlerEmbeddertest, OwnerPassword) {
-  ASSERT_TRUE(OpenDocument("encrypted.pdf", "5678"));
+  ASSERT_TRUE(OpenDocumentWithPassword("encrypted.pdf", "5678"));
   EXPECT_EQ(0xFFFFFFFC, FPDF_GetDocPermissions(document()));
 }
 
@@ -50,7 +50,7 @@
   const char md5[] = "a5dde3c6c37b8716b9b369a03752a728";
 #endif  // _FX_PLATFORM_ == _FX_PLATFORM_LINUX_
   {
-    ASSERT_TRUE(OpenDocument("encrypted.pdf", "5678", true));
+    ASSERT_TRUE(OpenDocumentWithOptions("encrypted.pdf", "5678", true));
     FPDF_PAGE page = LoadPage(0);
     ASSERT_TRUE(page);
     FPDF_PAGEOBJECT red_rect = FPDFPageObj_CreateNewRect(10, 10, 20, 20);
@@ -95,15 +95,15 @@
 }
 
 TEST_F(CPDFSecurityHandlerEmbeddertest, BadPasswordVersion5) {
-  ASSERT_FALSE(OpenDocument("bug_644.pdf", "tiger"));
+  ASSERT_FALSE(OpenDocumentWithPassword("bug_644.pdf", "tiger"));
 }
 
 TEST_F(CPDFSecurityHandlerEmbeddertest, OwnerPasswordVersion5) {
-  ASSERT_TRUE(OpenDocument("bug_644.pdf", "a"));
+  ASSERT_TRUE(OpenDocumentWithPassword("bug_644.pdf", "a"));
   EXPECT_EQ(0xFFFFFFFC, FPDF_GetDocPermissions(document()));
 }
 
 TEST_F(CPDFSecurityHandlerEmbeddertest, UserPasswordVersion5) {
-  ASSERT_TRUE(OpenDocument("bug_644.pdf", "b"));
+  ASSERT_TRUE(OpenDocumentWithPassword("bug_644.pdf", "b"));
   EXPECT_EQ(0xFFFFFFFC, FPDF_GetDocPermissions(document()));
 }
diff --git a/fpdfsdk/fpdfview_embeddertest.cpp b/fpdfsdk/fpdfview_embeddertest.cpp
index 5fedbfc..0055099 100644
--- a/fpdfsdk/fpdfview_embeddertest.cpp
+++ b/fpdfsdk/fpdfview_embeddertest.cpp
@@ -89,7 +89,7 @@
 }
 
 TEST_F(FPDFViewEmbeddertest, LinearizedDocument) {
-  EXPECT_TRUE(OpenDocument("feature_linearized_loading.pdf", nullptr, true));
+  EXPECT_TRUE(OpenDocumentLinearized("feature_linearized_loading.pdf"));
   int version;
   EXPECT_TRUE(FPDF_GetFileVersion(document(), &version));
   EXPECT_EQ(16, version);
diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp
index bb202bf..ccc98b4 100644
--- a/testing/embedder_test.cpp
+++ b/testing/embedder_test.cpp
@@ -131,9 +131,22 @@
   return true;
 }
 
-bool EmbedderTest::OpenDocument(const std::string& filename,
-                                const char* password,
-                                bool must_linearize) {
+bool EmbedderTest::OpenDocument(const std::string& filename) {
+  return OpenDocumentWithOptions(filename, nullptr, false);
+}
+
+bool EmbedderTest::OpenDocumentLinearized(const std::string& filename) {
+  return OpenDocumentWithOptions(filename, nullptr, true);
+}
+
+bool EmbedderTest::OpenDocumentWithPassword(const std::string& filename,
+                                            const char* password) {
+  return OpenDocumentWithOptions(filename, password, false);
+}
+
+bool EmbedderTest::OpenDocumentWithOptions(const std::string& filename,
+                                           const char* password,
+                                           bool must_linearize) {
   std::string file_path;
   if (!PathService::GetTestFilePath(filename, &file_path))
     return false;
diff --git a/testing/embedder_test.h b/testing/embedder_test.h
index 87c1fad..0315579 100644
--- a/testing/embedder_test.h
+++ b/testing/embedder_test.h
@@ -87,9 +87,16 @@
   // environment, or return false on failure.
   // The filename is relative to the test data directory where we store all the
   // test files.
-  virtual bool OpenDocument(const std::string& filename,
-                            const char* password = nullptr,
-                            bool must_linearize = false);
+  // |password| can be nullptr if there is none.
+  virtual bool OpenDocumentWithOptions(const std::string& filename,
+                                       const char* password,
+                                       bool must_linearize);
+
+  // Variants provided for convenience.
+  bool OpenDocument(const std::string& filename);
+  bool OpenDocumentLinearized(const std::string& filename);
+  bool OpenDocumentWithPassword(const std::string& filename,
+                                const char* password);
 
   // Perform JavaScript actions that are to run at document open time.
   void DoOpenActions();
diff --git a/testing/xfa_js_embedder_test.cpp b/testing/xfa_js_embedder_test.cpp
index db29729..d007c87 100644
--- a/testing/xfa_js_embedder_test.cpp
+++ b/testing/xfa_js_embedder_test.cpp
@@ -22,14 +22,14 @@
   v8::Isolate::CreateParams params;
   params.array_buffer_allocator = array_buffer_allocator_.get();
   isolate_ = v8::Isolate::New(params);
-  ASSERT_TRUE(isolate_ != nullptr);
+  ASSERT_TRUE(isolate_);
 
   EmbedderTest::SetExternalIsolate(isolate_);
   EmbedderTest::SetUp();
 }
 
 void XFAJSEmbedderTest::TearDown() {
-  value_ = nullptr;
+  value_.reset();
   script_context_ = nullptr;
 
   EmbedderTest::TearDown();
@@ -42,10 +42,11 @@
   return UnderlyingFromFPDFDocument(document())->GetXFADoc()->GetXFADoc();
 }
 
-bool XFAJSEmbedderTest::OpenDocument(const std::string& filename,
-                                     const char* password,
-                                     bool must_linearize) {
-  if (!EmbedderTest::OpenDocument(filename, password, must_linearize))
+bool XFAJSEmbedderTest::OpenDocumentWithOptions(const std::string& filename,
+                                                const char* password,
+                                                bool must_linearize) {
+  if (!EmbedderTest::OpenDocumentWithOptions(filename, password,
+                                             must_linearize))
     return false;
 
   script_context_ = GetXFADocument()->GetScriptContext();
diff --git a/testing/xfa_js_embedder_test.h b/testing/xfa_js_embedder_test.h
index 73d7d57..5f45496 100644
--- a/testing/xfa_js_embedder_test.h
+++ b/testing/xfa_js_embedder_test.h
@@ -22,12 +22,12 @@
   XFAJSEmbedderTest();
   ~XFAJSEmbedderTest() override;
 
+  // EmbedderTest:
   void SetUp() override;
   void TearDown() override;
-
-  bool OpenDocument(const std::string& filename,
-                    const char* password = nullptr,
-                    bool must_linearize = false) override;
+  bool OpenDocumentWithOptions(const std::string& filename,
+                               const char* password,
+                               bool must_linearize) override;
 
   v8::Isolate* GetIsolate() const { return isolate_; }
   CXFA_Document* GetXFADocument();
@@ -40,8 +40,8 @@
  private:
   std::unique_ptr<FXJS_ArrayBufferAllocator> array_buffer_allocator_;
   std::unique_ptr<CFXJSE_Value> value_;
-  v8::Isolate* isolate_;
-  CFXJSE_Engine* script_context_;
+  v8::Isolate* isolate_ = nullptr;
+  CFXJSE_Engine* script_context_ = nullptr;
 
   bool ExecuteHelper(const ByteStringView& input);
 };