Skip to content

Commit 0c30768

Browse files
committed
[test] silent printing with footer option
1 parent c800a50 commit 0c30768

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

src/nwjs_browsertest.cc

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,11 @@ class NWWebViewTestBase : public extensions::PlatformAppBrowserTest {
533533
command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc");
534534

535535
extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line);
536+
PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir_);
537+
test_data_dir_ = test_data_dir_.Append(FILE_PATH_LITERAL("content"));
538+
test_data_dir_ = test_data_dir_.Append(FILE_PATH_LITERAL("nw"));
539+
test_data_dir_ = test_data_dir_.Append(FILE_PATH_LITERAL("test"));
540+
test_data_dir_ = test_data_dir_.Append(FILE_PATH_LITERAL("data"));
536541
}
537542

538543
// Handles |request| by serving a redirect response if the |User-Agent| is
@@ -857,11 +862,6 @@ class NWJSWebViewTest : public NWWebViewTestBase, public testing::WithParamInter
857862

858863
void SetUpCommandLine(base::CommandLine* command_line) override {
859864
NWWebViewTestBase::SetUpCommandLine(command_line);
860-
PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir_);
861-
test_data_dir_ = test_data_dir_.Append(FILE_PATH_LITERAL("content"));
862-
test_data_dir_ = test_data_dir_.Append(FILE_PATH_LITERAL("nw"));
863-
test_data_dir_ = test_data_dir_.Append(FILE_PATH_LITERAL("test"));
864-
test_data_dir_ = test_data_dir_.Append(FILE_PATH_LITERAL("data"));
865865

866866
trusted_ = GetParam();
867867
}
@@ -871,6 +871,8 @@ class NWJSWebViewTest : public NWWebViewTestBase, public testing::WithParamInter
871871

872872
INSTANTIATE_TEST_CASE_P(NWJSWebViewTests, NWJSWebViewTest, testing::Bool());
873873

874+
class NWJSWebViewTestF: public NWWebViewTestBase {};
875+
874876
class NWAppTest : public extensions::PlatformAppBrowserTest {
875877
public:
876878
NWAppTest() {}
@@ -1006,17 +1008,45 @@ void CountFrames(int* frame_count,
10061008
++(*frame_count);
10071009
}
10081010

1009-
std::string g_tree_dump;
1010-
void CheckPdfPluginForRenderFrame(content::RenderFrameHost* frame) {
1011+
void DumpAxTree(std::string* dump_output, content::RenderFrameHost* frame) {
10111012
content::RenderFrameHostImpl* f = static_cast<content::RenderFrameHostImpl*>(frame);
10121013
content::BrowserAccessibilityManager* manager = f->GetOrCreateBrowserAccessibilityManager();
10131014
ui::AXTreeUpdate ax_tree = manager->SnapshotAXTreeForTesting();
10141015
std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree);
1015-
g_tree_dump += ax_tree_dump;
1016+
*dump_output += ax_tree_dump;
10161017
}
10171018

10181019
} //namespace
10191020

1021+
IN_PROC_BROWSER_TEST_F(NWJSWebViewTestF, SilentPrintChangeFooter) {
1022+
content::BrowserAccessibilityState::GetInstance()->EnableAccessibility();
1023+
LoadAndLaunchPlatformApp("silent_print", "Launched");
1024+
content::WebContents* web_contents = GetFirstAppWindowWebContents();
1025+
ASSERT_TRUE(web_contents);
1026+
ExtensionTestMessageListener listener("Loaded", false);
1027+
ASSERT_TRUE(content::ExecuteScript(web_contents, "document.getElementById('testbtn').click()"));
1028+
EXPECT_TRUE(listener.WaitUntilSatisfied()) << "'" << listener.message()
1029+
<< "' message was not receieved";
1030+
1031+
std::vector<content::WebContents*> guest_web_contents_list;
1032+
unsigned long n_guests = 2;
1033+
LOG(WARNING) << "WaitForNumGuestsCreated";
1034+
GetGuestViewManager()->WaitForNumGuestsCreated(n_guests);
1035+
GetGuestViewManager()->GetGuestWebContentsList(&guest_web_contents_list);
1036+
ASSERT_EQ(n_guests, guest_web_contents_list.size());
1037+
1038+
content::WebContents* web_view_contents = guest_web_contents_list[0];
1039+
bool load_success = pdf_extension_test_util::EnsurePDFHasLoaded(
1040+
web_view_contents);
1041+
EXPECT_TRUE(load_success);
1042+
WaitForAccessibilityTreeToContainNodeWithName(web_view_contents, "hello world\r\n");
1043+
std::string tree_dump;
1044+
// Make sure all the frames in the dialog has access to the PDF plugin.
1045+
guest_web_contents_list[1]->ForEachFrame(base::Bind(&DumpAxTree, base::Unretained(&tree_dump)));
1046+
LOG(INFO) << "ax tree: " << tree_dump;
1047+
EXPECT_TRUE(tree_dump.find("nwtestfooter") != std::string::npos);
1048+
}
1049+
10201050
IN_PROC_BROWSER_TEST_F(NWJSAppTest, PrintChangeFooter) {
10211051
content::BrowserAccessibilityState::GetInstance()->EnableAccessibility();
10221052
LoadAndLaunchPlatformApp("print_test", "Launched");
@@ -1040,9 +1070,10 @@ IN_PROC_BROWSER_TEST_F(NWJSAppTest, PrintChangeFooter) {
10401070
} while (frame_count < kExpectedFrameCount);
10411071
ASSERT_EQ(kExpectedFrameCount, frame_count);
10421072
WaitForAccessibilityTreeToContainNodeWithName(preview_dialog, "hello world\r\n");
1073+
std::string tree_dump;
10431074
// Make sure all the frames in the dialog has access to the PDF plugin.
1044-
preview_dialog->ForEachFrame(base::Bind(&CheckPdfPluginForRenderFrame));
1045-
EXPECT_TRUE(g_tree_dump.find("nwtestfooter") != std::string::npos);
1075+
preview_dialog->ForEachFrame(base::Bind(&DumpAxTree, base::Unretained(&tree_dump)));
1076+
EXPECT_TRUE(tree_dump.find("nwtestfooter") != std::string::npos);
10461077
}
10471078

10481079
IN_PROC_BROWSER_TEST_P(NWJSWebViewTest, LocalPDF) {

0 commit comments

Comments
 (0)