54
54
#include " components/guest_view/browser/guest_view_manager_factory.h"
55
55
#include " components/guest_view/browser/test_guest_view_manager.h"
56
56
#include " content/public/browser/ax_event_notification_details.h"
57
+ #include " content/public/browser/browser_accessibility_state.h"
57
58
#include " content/public/browser/browser_child_process_host_iterator.h"
58
59
#include " content/public/browser/child_process_data.h"
59
60
#include " content/public/common/process_type.h"
97
98
#include " ui/views/view.h"
98
99
#include " ui/views/widget/widget.h"
99
100
101
+ #include " chrome/browser/printing/print_preview_dialog_controller.h"
102
+ #include " content/browser/frame_host/render_frame_host_impl.h"
103
+
100
104
#if defined(ENABLE_PLUGINS)
101
105
#include " content/public/browser/plugin_service.h"
102
106
#include " content/public/common/webplugininfo.h"
@@ -122,6 +126,7 @@ using task_manager::browsertest_util::MatchWebView;
122
126
using task_manager::browsertest_util::WaitForTaskManagerRows;
123
127
using ui::MenuModel;
124
128
using content::BrowserThread;
129
+ using content::WebContents;
125
130
126
131
namespace {
127
132
const char kEmptyResponsePath [] = " /close-socket" ;
@@ -899,6 +904,8 @@ class NWAppTest : public extensions::PlatformAppBrowserTest {
899
904
900
905
};
901
906
907
+ class NWJSAppTest : public NWAppTest {};
908
+
902
909
void NWTimeoutCallback (const std::string& timeout_message) {
903
910
base::MessageLoop::current ()->QuitWhenIdle ();
904
911
}
@@ -923,6 +930,121 @@ IN_PROC_BROWSER_TEST_F(NWAppTest, LocalFlash) {
923
930
EXPECT_EQ (expected_title, title_watcher.WaitAndGetTitle ());
924
931
}
925
932
933
+ namespace {
934
+ class PrintDialogWaiter {
935
+ public:
936
+ PrintDialogWaiter (content::WebContents* web_contents)
937
+ : web_contents_(web_contents) {}
938
+
939
+ WebContents* Wait () {
940
+ WebContents* ret;
941
+ if ((ret = CheckDlg ()))
942
+ return ret;
943
+
944
+ base::RepeatingTimer check_timer;
945
+ check_timer.Start (
946
+ FROM_HERE,
947
+ base::TimeDelta::FromMilliseconds (200 ),
948
+ this ,
949
+ &PrintDialogWaiter::OnTimer);
950
+
951
+ runner_ = new content::MessageLoopRunner;
952
+ runner_->Run ();
953
+ return CheckDlg ();
954
+ }
955
+
956
+ private:
957
+ WebContents* CheckDlg () {
958
+ printing::PrintPreviewDialogController* dialog_controller =
959
+ printing::PrintPreviewDialogController::GetInstance ();
960
+ return dialog_controller->GetPrintPreviewForContents (web_contents_);
961
+ }
962
+
963
+ void OnTimer () {
964
+ DCHECK (runner_.get ());
965
+ if (CheckDlg ())
966
+ runner_->Quit ();
967
+ }
968
+ content::WebContents* web_contents_;
969
+ scoped_refptr<content::MessageLoopRunner> runner_;
970
+
971
+ DISALLOW_COPY_AND_ASSIGN (PrintDialogWaiter);
972
+ };
973
+
974
+ static std::string DumpPdfAccessibilityTree (const ui::AXTreeUpdate& ax_tree) {
975
+ // Create a string representation of the tree starting with the embedded
976
+ // object.
977
+ std::string ax_tree_dump;
978
+ base::hash_map<int32_t , int > id_to_indentation;
979
+ // bool found_embedded_object = false;
980
+ for (auto & node : ax_tree.nodes ) {
981
+ #if 0
982
+ if (node.role == ui::AX_ROLE_EMBEDDED_OBJECT)
983
+ found_embedded_object = true;
984
+ if (!found_embedded_object)
985
+ continue;
986
+ #endif
987
+ int indent = id_to_indentation[node.id ];
988
+ ax_tree_dump += std::string (2 * indent, ' ' );
989
+ ax_tree_dump += ui::ToString (node.role );
990
+
991
+ std::string name = node.GetStringAttribute (ui::AX_ATTR_NAME);
992
+ base::ReplaceChars (name, " \r " , " \\ r" , &name);
993
+ base::ReplaceChars (name, " \n " , " \\ n" , &name);
994
+ if (!name.empty ())
995
+ ax_tree_dump += " '" + name + " '" ;
996
+ ax_tree_dump += " \n " ;
997
+ for (size_t j = 0 ; j < node.child_ids .size (); ++j)
998
+ id_to_indentation[node.child_ids [j]] = indent + 1 ;
999
+ }
1000
+
1001
+ return ax_tree_dump;
1002
+ }
1003
+
1004
+ void CountFrames (int * frame_count,
1005
+ content::RenderFrameHost* frame) {
1006
+ ++(*frame_count);
1007
+ }
1008
+
1009
+ std::string g_tree_dump;
1010
+ void CheckPdfPluginForRenderFrame (content::RenderFrameHost* frame) {
1011
+ content::RenderFrameHostImpl* f = static_cast <content::RenderFrameHostImpl*>(frame);
1012
+ content::BrowserAccessibilityManager* manager = f->GetOrCreateBrowserAccessibilityManager ();
1013
+ ui::AXTreeUpdate ax_tree = manager->SnapshotAXTreeForTesting ();
1014
+ std::string ax_tree_dump = DumpPdfAccessibilityTree (ax_tree);
1015
+ g_tree_dump += ax_tree_dump;
1016
+ }
1017
+
1018
+ } // namespace
1019
+
1020
+ IN_PROC_BROWSER_TEST_F (NWJSAppTest, PrintChangeFooter) {
1021
+ content::BrowserAccessibilityState::GetInstance ()->EnableAccessibility ();
1022
+ LoadAndLaunchPlatformApp (" print_test" , " Launched" );
1023
+ content::WebContents* web_contents = GetFirstAppWindowWebContents ();
1024
+ ASSERT_TRUE (web_contents);
1025
+ ASSERT_TRUE (content::ExecuteScript (web_contents, " document.getElementById('testbtn').click()" ));
1026
+ LOG (INFO) << " waiting for print dialog" ;
1027
+ WebContents* preview_dialog = PrintDialogWaiter (web_contents).Wait ();
1028
+ LOG (INFO) << " done" ;
1029
+ const int kExpectedFrameCount = 2 ;
1030
+ int frame_count;
1031
+ do {
1032
+ base::RunLoop run_loop;
1033
+ base::ThreadTaskRunnerHandle::Get ()->PostDelayedTask (
1034
+ FROM_HERE, run_loop.QuitClosure (), base::TimeDelta::FromSeconds (1 ));
1035
+ run_loop.Run ();
1036
+
1037
+ frame_count = 0 ;
1038
+ preview_dialog->ForEachFrame (
1039
+ base::Bind (&CountFrames, base::Unretained (&frame_count)));
1040
+ } while (frame_count < kExpectedFrameCount );
1041
+ ASSERT_EQ (kExpectedFrameCount , frame_count);
1042
+ WaitForAccessibilityTreeToContainNodeWithName (preview_dialog, " hello world\r\n " );
1043
+ // 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);
1046
+ }
1047
+
926
1048
IN_PROC_BROWSER_TEST_P (NWJSWebViewTest, LocalPDF) {
927
1049
std::string contents;
928
1050
base::FilePath test_dir = test_data_dir_.Append (FILE_PATH_LITERAL (" platform_apps" )).Append (FILE_PATH_LITERAL (" local_pdf" ));
0 commit comments