OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "apps/launcher.h" | 9 #include "apps/launcher.h" |
10 #include "base/auto_reset.h" | |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
13 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
18 #include "chrome/app/chrome_command_ids.h" | 19 #include "chrome/app/chrome_command_ids.h" |
19 #include "chrome/browser/apps/app_browsertest_util.h" | 20 #include "chrome/browser/apps/app_browsertest_util.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
35 #include "chrome/test/base/test_switches.h" | 36 #include "chrome/test/base/test_switches.h" |
36 #include "chrome/test/base/ui_test_utils.h" | 37 #include "chrome/test/base/ui_test_utils.h" |
37 #include "components/pref_registry/pref_registry_syncable.h" | 38 #include "components/pref_registry/pref_registry_syncable.h" |
38 #include "components/prefs/pref_service.h" | 39 #include "components/prefs/pref_service.h" |
39 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 40 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
40 #include "content/public/browser/devtools_agent_host.h" | 41 #include "content/public/browser/devtools_agent_host.h" |
41 #include "content/public/browser/host_zoom_map.h" | 42 #include "content/public/browser/host_zoom_map.h" |
42 #include "content/public/browser/render_process_host.h" | 43 #include "content/public/browser/render_process_host.h" |
43 #include "content/public/browser/render_widget_host_view.h" | 44 #include "content/public/browser/render_widget_host_view.h" |
44 #include "content/public/test/browser_test_utils.h" | 45 #include "content/public/test/browser_test_utils.h" |
45 #include "content/public/test/test_utils.h" | |
46 #include "extensions/browser/app_window/app_window.h" | 46 #include "extensions/browser/app_window/app_window.h" |
47 #include "extensions/browser/app_window/app_window_registry.h" | 47 #include "extensions/browser/app_window/app_window_registry.h" |
48 #include "extensions/browser/app_window/native_app_window.h" | 48 #include "extensions/browser/app_window/native_app_window.h" |
49 #include "extensions/browser/event_router.h" | 49 #include "extensions/browser/event_router.h" |
50 #include "extensions/browser/extension_prefs.h" | 50 #include "extensions/browser/extension_prefs.h" |
51 #include "extensions/browser/extension_registry.h" | 51 #include "extensions/browser/extension_registry.h" |
52 #include "extensions/browser/extension_registry_observer.h" | 52 #include "extensions/browser/extension_registry_observer.h" |
53 #include "extensions/browser/pref_names.h" | 53 #include "extensions/browser/pref_names.h" |
54 #include "extensions/common/api/app_runtime.h" | 54 #include "extensions/common/api/app_runtime.h" |
55 #include "extensions/common/constants.h" | 55 #include "extensions/common/constants.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 private: | 116 private: |
117 size_t observations_; | 117 size_t observations_; |
118 std::vector<content::WebContents*> observed_tabs_; | 118 std::vector<content::WebContents*> observed_tabs_; |
119 | 119 |
120 DISALLOW_COPY_AND_ASSIGN(TabsAddedNotificationObserver); | 120 DISALLOW_COPY_AND_ASSIGN(TabsAddedNotificationObserver); |
121 }; | 121 }; |
122 | 122 |
123 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 123 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
124 class ScopedPreviewTestingDelegate : PrintPreviewUI::TestingDelegate { | 124 class ScopedPreviewTestingDelegate : PrintPreviewUI::TestingDelegate { |
125 public: | 125 public: |
126 explicit ScopedPreviewTestingDelegate(bool auto_cancel) | 126 ScopedPreviewTestingDelegate() |
127 : auto_cancel_(auto_cancel), | 127 : total_page_count_(1), |
128 total_page_count_(1), | |
129 rendered_page_count_(0) { | 128 rendered_page_count_(0) { |
130 PrintPreviewUI::SetDelegateForTesting(this); | 129 PrintPreviewUI::SetDelegateForTesting(this); |
131 } | 130 } |
132 | 131 |
133 ~ScopedPreviewTestingDelegate() { | 132 ~ScopedPreviewTestingDelegate() { |
134 PrintPreviewUI::SetDelegateForTesting(NULL); | 133 PrintPreviewUI::SetDelegateForTesting(NULL); |
135 } | 134 } |
136 | 135 |
137 // PrintPreviewUI::TestingDelegate implementation. | 136 // PrintPreviewUI::TestingDelegate implementation. |
138 bool IsAutoCancelEnabled() override { return auto_cancel_; } | |
139 | |
140 // PrintPreviewUI::TestingDelegate implementation. | |
141 void DidGetPreviewPageCount(int page_count) override { | 137 void DidGetPreviewPageCount(int page_count) override { |
142 total_page_count_ = page_count; | 138 total_page_count_ = page_count; |
143 } | 139 } |
144 | 140 |
145 // PrintPreviewUI::TestingDelegate implementation. | 141 // PrintPreviewUI::TestingDelegate implementation. |
146 void DidRenderPreviewPage(content::WebContents* preview_dialog) override { | 142 void DidRenderPreviewPage(content::WebContents* preview_dialog) override { |
147 dialog_size_ = preview_dialog->GetContainerBounds().size(); | 143 dialog_size_ = preview_dialog->GetContainerBounds().size(); |
148 ++rendered_page_count_; | 144 ++rendered_page_count_; |
149 CHECK(rendered_page_count_ <= total_page_count_); | 145 CHECK(rendered_page_count_ <= total_page_count_); |
150 if (waiting_runner_.get() && rendered_page_count_ == total_page_count_) { | 146 if (rendered_page_count_ == total_page_count_ && run_loop_) { |
151 waiting_runner_->Quit(); | 147 run_loop_->Quit(); |
152 } | 148 } |
153 } | 149 } |
154 | 150 |
155 void WaitUntilPreviewIsReady() { | 151 void WaitUntilPreviewIsReady() { |
156 CHECK(!waiting_runner_.get()); | 152 if (rendered_page_count_ >= total_page_count_) |
157 if (rendered_page_count_ < total_page_count_) { | 153 return; |
158 waiting_runner_ = new content::MessageLoopRunner; | 154 |
159 waiting_runner_->Run(); | 155 base::RunLoop run_loop; |
160 waiting_runner_ = NULL; | 156 base::AutoReset<base::RunLoop*> auto_reset(&run_loop_, &run_loop); |
161 } | 157 run_loop.Run(); |
162 } | 158 } |
163 | 159 |
164 gfx::Size dialog_size() { | 160 gfx::Size dialog_size() { |
165 return dialog_size_; | 161 return dialog_size_; |
166 } | 162 } |
167 | 163 |
168 private: | 164 private: |
169 bool auto_cancel_; | |
170 int total_page_count_; | 165 int total_page_count_; |
tapted
2017/02/09 02:03:02
nit: move the = 1 down here (and = 0 below) rather
rbpotter
2017/02/09 20:11:46
Done.
| |
171 int rendered_page_count_; | 166 int rendered_page_count_; |
172 scoped_refptr<content::MessageLoopRunner> waiting_runner_; | 167 base::RunLoop* run_loop_ = nullptr; |
173 gfx::Size dialog_size_; | 168 gfx::Size dialog_size_; |
174 }; | 169 }; |
175 | 170 |
176 #endif // ENABLE_PRINT_PREVIEW | 171 #endif // ENABLE_PRINT_PREVIEW |
177 | 172 |
178 #if !defined(OS_CHROMEOS) && !defined(OS_WIN) | 173 #if !defined(OS_CHROMEOS) && !defined(OS_WIN) |
179 bool CopyTestDataAndGetTestFilePath( | 174 bool CopyTestDataAndGetTestFilePath( |
180 const base::FilePath& test_data_file, | 175 const base::FilePath& test_data_file, |
181 const base::FilePath& temp_dir, | 176 const base::FilePath& temp_dir, |
182 const char* filename, | 177 const char* filename, |
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1131 | 1126 |
1132 EXPECT_EQ(1LU, GetAppWindowCount()); | 1127 EXPECT_EQ(1LU, GetAppWindowCount()); |
1133 EXPECT_TRUE(GetFirstAppWindow() | 1128 EXPECT_TRUE(GetFirstAppWindow() |
1134 ->web_contents() | 1129 ->web_contents() |
1135 ->GetRenderWidgetHostView() | 1130 ->GetRenderWidgetHostView() |
1136 ->HasFocus()); | 1131 ->HasFocus()); |
1137 } | 1132 } |
1138 | 1133 |
1139 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 1134 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
1140 | 1135 |
1141 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) | |
1142 #define MAYBE_WindowDotPrintShouldBringUpPrintPreview \ | |
1143 DISABLED_WindowDotPrintShouldBringUpPrintPreview | |
1144 #else | |
1145 #define MAYBE_WindowDotPrintShouldBringUpPrintPreview \ | |
1146 WindowDotPrintShouldBringUpPrintPreview | |
1147 #endif | |
1148 | |
1149 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, | 1136 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
1150 MAYBE_WindowDotPrintShouldBringUpPrintPreview) { | 1137 WindowDotPrintShouldBringUpPrintPreview) { |
1151 ScopedPreviewTestingDelegate preview_delegate(true); | 1138 ScopedPreviewTestingDelegate preview_delegate; |
1152 ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_; | 1139 ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_; |
1153 preview_delegate.WaitUntilPreviewIsReady(); | 1140 preview_delegate.WaitUntilPreviewIsReady(); |
1154 } | 1141 } |
1155 | 1142 |
1156 // This test verifies that http://crbug.com/297179 is fixed. | 1143 // This test verifies that http://crbug.com/297179 is fixed. |
1157 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, | 1144 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
1158 DISABLED_ClosingWindowWhilePrintingShouldNotCrash) { | 1145 DISABLED_ClosingWindowWhilePrintingShouldNotCrash) { |
1159 ScopedPreviewTestingDelegate preview_delegate(false); | 1146 ScopedPreviewTestingDelegate preview_delegate; |
1160 ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_; | 1147 ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_; |
1161 preview_delegate.WaitUntilPreviewIsReady(); | 1148 preview_delegate.WaitUntilPreviewIsReady(); |
1162 GetFirstAppWindow()->GetBaseWindow()->Close(); | 1149 GetFirstAppWindow()->GetBaseWindow()->Close(); |
1163 } | 1150 } |
1164 | 1151 |
1165 // This test currently only passes on OS X (on other platforms the print preview | 1152 // This test currently only passes on OS X (on other platforms the print preview |
1166 // dialog's size is limited by the size of the window being printed). | 1153 // dialog's size is limited by the size of the window being printed). |
1167 #if !defined(OS_MACOSX) | 1154 #if !defined(OS_MACOSX) |
1168 #define MAYBE_PrintPreviewShouldNotBeTooSmall \ | 1155 #define MAYBE_PrintPreviewShouldNotBeTooSmall \ |
1169 DISABLED_PrintPreviewShouldNotBeTooSmall | 1156 DISABLED_PrintPreviewShouldNotBeTooSmall |
1170 #else | 1157 #else |
1171 #define MAYBE_PrintPreviewShouldNotBeTooSmall \ | 1158 #define MAYBE_PrintPreviewShouldNotBeTooSmall \ |
1172 PrintPreviewShouldNotBeTooSmall | 1159 PrintPreviewShouldNotBeTooSmall |
1173 #endif | 1160 #endif |
1174 | 1161 |
1175 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, | 1162 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
1176 MAYBE_PrintPreviewShouldNotBeTooSmall) { | 1163 MAYBE_PrintPreviewShouldNotBeTooSmall) { |
1177 // Print preview dialogs with widths less than 410 pixels will have preview | 1164 // Print preview dialogs with widths less than 410 pixels will have preview |
1178 // areas that are too small, and ones with heights less than 191 pixels will | 1165 // areas that are too small, and ones with heights less than 191 pixels will |
1179 // have vertical scrollers for their controls that are too small. | 1166 // have vertical scrollers for their controls that are too small. |
1180 gfx::Size minimum_dialog_size(410, 191); | 1167 gfx::Size minimum_dialog_size(410, 191); |
1181 ScopedPreviewTestingDelegate preview_delegate(false); | 1168 ScopedPreviewTestingDelegate preview_delegate; |
1182 ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_; | 1169 ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_; |
1183 preview_delegate.WaitUntilPreviewIsReady(); | 1170 preview_delegate.WaitUntilPreviewIsReady(); |
1184 EXPECT_GE(preview_delegate.dialog_size().width(), | 1171 EXPECT_GE(preview_delegate.dialog_size().width(), |
1185 minimum_dialog_size.width()); | 1172 minimum_dialog_size.width()); |
1186 EXPECT_GE(preview_delegate.dialog_size().height(), | 1173 EXPECT_GE(preview_delegate.dialog_size().height(), |
1187 minimum_dialog_size.height()); | 1174 minimum_dialog_size.height()); |
1188 GetFirstAppWindow()->GetBaseWindow()->Close(); | 1175 GetFirstAppWindow()->GetBaseWindow()->Close(); |
1189 } | 1176 } |
1190 #endif // ENABLE_PRINT_PREVIEW | 1177 #endif // ENABLE_PRINT_PREVIEW |
1191 | 1178 |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1379 // https://crbug.com/620194. | 1366 // https://crbug.com/620194. |
1380 #define MAYBE_AppWindowIframe DISABLED_AppWindowIframe | 1367 #define MAYBE_AppWindowIframe DISABLED_AppWindowIframe |
1381 // Sends chrome.test.sendMessage from chrome.app.window.create's callback. | 1368 // Sends chrome.test.sendMessage from chrome.app.window.create's callback. |
1382 // The app window also adds an <iframe> to the page during window.onload. | 1369 // The app window also adds an <iframe> to the page during window.onload. |
1383 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_AppWindowIframe) { | 1370 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_AppWindowIframe) { |
1384 LoadAndLaunchPlatformApp("app_window_send_message", | 1371 LoadAndLaunchPlatformApp("app_window_send_message", |
1385 "APP_WINDOW_CREATE_CALLBACK"); | 1372 "APP_WINDOW_CREATE_CALLBACK"); |
1386 } | 1373 } |
1387 | 1374 |
1388 } // namespace extensions | 1375 } // namespace extensions |
OLD | NEW |