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), | |
128 total_page_count_(1), | |
129 rendered_page_count_(0) { | |
130 PrintPreviewUI::SetDelegateForTesting(this); | 127 PrintPreviewUI::SetDelegateForTesting(this); |
131 } | 128 } |
132 | 129 |
133 ~ScopedPreviewTestingDelegate() { | 130 ~ScopedPreviewTestingDelegate() { |
134 PrintPreviewUI::SetDelegateForTesting(NULL); | 131 PrintPreviewUI::SetDelegateForTesting(NULL); |
135 } | 132 } |
136 | 133 |
137 // PrintPreviewUI::TestingDelegate implementation. | 134 // PrintPreviewUI::TestingDelegate implementation. |
138 bool IsAutoCancelEnabled() override { return auto_cancel_; } | |
139 | |
140 // PrintPreviewUI::TestingDelegate implementation. | |
141 void DidGetPreviewPageCount(int page_count) override { | 135 void DidGetPreviewPageCount(int page_count) override { |
142 total_page_count_ = page_count; | 136 total_page_count_ = page_count; |
143 } | 137 } |
144 | 138 |
145 // PrintPreviewUI::TestingDelegate implementation. | 139 // PrintPreviewUI::TestingDelegate implementation. |
146 void DidRenderPreviewPage(content::WebContents* preview_dialog) override { | 140 void DidRenderPreviewPage(content::WebContents* preview_dialog) override { |
147 dialog_size_ = preview_dialog->GetContainerBounds().size(); | 141 dialog_size_ = preview_dialog->GetContainerBounds().size(); |
148 ++rendered_page_count_; | 142 ++rendered_page_count_; |
149 CHECK(rendered_page_count_ <= total_page_count_); | 143 CHECK(rendered_page_count_ <= total_page_count_); |
150 if (waiting_runner_.get() && rendered_page_count_ == total_page_count_) { | 144 if (rendered_page_count_ == total_page_count_ && run_loop_) { |
151 waiting_runner_->Quit(); | 145 run_loop_->Quit(); |
152 } | 146 } |
153 } | 147 } |
154 | 148 |
155 void WaitUntilPreviewIsReady() { | 149 void WaitUntilPreviewIsReady() { |
156 CHECK(!waiting_runner_.get()); | 150 if (rendered_page_count_ >= total_page_count_) |
157 if (rendered_page_count_ < total_page_count_) { | 151 return; |
158 waiting_runner_ = new content::MessageLoopRunner; | 152 |
159 waiting_runner_->Run(); | 153 base::RunLoop run_loop; |
160 waiting_runner_ = NULL; | 154 base::AutoReset<base::RunLoop*> auto_reset(&run_loop_, &run_loop); |
161 } | 155 run_loop.Run(); |
162 } | 156 } |
163 | 157 |
164 gfx::Size dialog_size() { | 158 gfx::Size dialog_size() { |
165 return dialog_size_; | 159 return dialog_size_; |
166 } | 160 } |
167 | 161 |
168 private: | 162 private: |
169 bool auto_cancel_; | 163 int total_page_count_ = 1; |
170 int total_page_count_; | 164 int rendered_page_count_ = 0; |
171 int rendered_page_count_; | 165 base::RunLoop* run_loop_ = nullptr; |
172 scoped_refptr<content::MessageLoopRunner> waiting_runner_; | |
173 gfx::Size dialog_size_; | 166 gfx::Size dialog_size_; |
174 }; | 167 }; |
175 | 168 |
176 #endif // ENABLE_PRINT_PREVIEW | 169 #endif // ENABLE_PRINT_PREVIEW |
177 | 170 |
178 #if !defined(OS_CHROMEOS) && !defined(OS_WIN) | 171 #if !defined(OS_CHROMEOS) && !defined(OS_WIN) |
179 bool CopyTestDataAndGetTestFilePath( | 172 bool CopyTestDataAndGetTestFilePath( |
180 const base::FilePath& test_data_file, | 173 const base::FilePath& test_data_file, |
181 const base::FilePath& temp_dir, | 174 const base::FilePath& temp_dir, |
182 const char* filename, | 175 const char* filename, |
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1131 | 1124 |
1132 EXPECT_EQ(1LU, GetAppWindowCount()); | 1125 EXPECT_EQ(1LU, GetAppWindowCount()); |
1133 EXPECT_TRUE(GetFirstAppWindow() | 1126 EXPECT_TRUE(GetFirstAppWindow() |
1134 ->web_contents() | 1127 ->web_contents() |
1135 ->GetRenderWidgetHostView() | 1128 ->GetRenderWidgetHostView() |
1136 ->HasFocus()); | 1129 ->HasFocus()); |
1137 } | 1130 } |
1138 | 1131 |
1139 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 1132 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
1140 | 1133 |
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, | 1134 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
1150 MAYBE_WindowDotPrintShouldBringUpPrintPreview) { | 1135 WindowDotPrintShouldBringUpPrintPreview) { |
1151 ScopedPreviewTestingDelegate preview_delegate(true); | 1136 ScopedPreviewTestingDelegate preview_delegate; |
1152 ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_; | 1137 ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_; |
1153 preview_delegate.WaitUntilPreviewIsReady(); | 1138 preview_delegate.WaitUntilPreviewIsReady(); |
1154 } | 1139 } |
1155 | 1140 |
1156 // This test verifies that http://crbug.com/297179 is fixed. | 1141 // This test verifies that http://crbug.com/297179 is fixed. |
1157 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, | 1142 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
1158 DISABLED_ClosingWindowWhilePrintingShouldNotCrash) { | 1143 DISABLED_ClosingWindowWhilePrintingShouldNotCrash) { |
1159 ScopedPreviewTestingDelegate preview_delegate(false); | 1144 ScopedPreviewTestingDelegate preview_delegate; |
1160 ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_; | 1145 ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_; |
1161 preview_delegate.WaitUntilPreviewIsReady(); | 1146 preview_delegate.WaitUntilPreviewIsReady(); |
1162 GetFirstAppWindow()->GetBaseWindow()->Close(); | 1147 GetFirstAppWindow()->GetBaseWindow()->Close(); |
1163 } | 1148 } |
1164 | 1149 |
1165 // This test currently only passes on OS X (on other platforms the print preview | 1150 // 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). | 1151 // dialog's size is limited by the size of the window being printed). |
1167 #if !defined(OS_MACOSX) | 1152 #if !defined(OS_MACOSX) |
1168 #define MAYBE_PrintPreviewShouldNotBeTooSmall \ | 1153 #define MAYBE_PrintPreviewShouldNotBeTooSmall \ |
1169 DISABLED_PrintPreviewShouldNotBeTooSmall | 1154 DISABLED_PrintPreviewShouldNotBeTooSmall |
1170 #else | 1155 #else |
1171 #define MAYBE_PrintPreviewShouldNotBeTooSmall \ | 1156 #define MAYBE_PrintPreviewShouldNotBeTooSmall \ |
1172 PrintPreviewShouldNotBeTooSmall | 1157 PrintPreviewShouldNotBeTooSmall |
1173 #endif | 1158 #endif |
1174 | 1159 |
1175 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, | 1160 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
1176 MAYBE_PrintPreviewShouldNotBeTooSmall) { | 1161 MAYBE_PrintPreviewShouldNotBeTooSmall) { |
1177 // Print preview dialogs with widths less than 410 pixels will have preview | 1162 // 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 | 1163 // 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. | 1164 // have vertical scrollers for their controls that are too small. |
1180 gfx::Size minimum_dialog_size(410, 191); | 1165 gfx::Size minimum_dialog_size(410, 191); |
1181 ScopedPreviewTestingDelegate preview_delegate(false); | 1166 ScopedPreviewTestingDelegate preview_delegate; |
1182 ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_; | 1167 ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_; |
1183 preview_delegate.WaitUntilPreviewIsReady(); | 1168 preview_delegate.WaitUntilPreviewIsReady(); |
1184 EXPECT_GE(preview_delegate.dialog_size().width(), | 1169 EXPECT_GE(preview_delegate.dialog_size().width(), |
1185 minimum_dialog_size.width()); | 1170 minimum_dialog_size.width()); |
1186 EXPECT_GE(preview_delegate.dialog_size().height(), | 1171 EXPECT_GE(preview_delegate.dialog_size().height(), |
1187 minimum_dialog_size.height()); | 1172 minimum_dialog_size.height()); |
1188 GetFirstAppWindow()->GetBaseWindow()->Close(); | 1173 GetFirstAppWindow()->GetBaseWindow()->Close(); |
1189 } | 1174 } |
1190 #endif // ENABLE_PRINT_PREVIEW | 1175 #endif // ENABLE_PRINT_PREVIEW |
1191 | 1176 |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 // https://crbug.com/620194. | 1364 // https://crbug.com/620194. |
1380 #define MAYBE_AppWindowIframe DISABLED_AppWindowIframe | 1365 #define MAYBE_AppWindowIframe DISABLED_AppWindowIframe |
1381 // Sends chrome.test.sendMessage from chrome.app.window.create's callback. | 1366 // 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. | 1367 // The app window also adds an <iframe> to the page during window.onload. |
1383 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_AppWindowIframe) { | 1368 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_AppWindowIframe) { |
1384 LoadAndLaunchPlatformApp("app_window_send_message", | 1369 LoadAndLaunchPlatformApp("app_window_send_message", |
1385 "APP_WINDOW_CREATE_CALLBACK"); | 1370 "APP_WINDOW_CREATE_CALLBACK"); |
1386 } | 1371 } |
1387 | 1372 |
1388 } // namespace extensions | 1373 } // namespace extensions |
OLD | NEW |