OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
11 #include "chrome/browser/extensions/tab_helper.h" | 11 #include "chrome/browser/extensions/tab_helper.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
16 #include "chrome/browser/ui/tabs/tab_utils.h" | 15 #include "chrome/browser/ui/tabs/tab_utils.h" |
17 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/chrome_version_info.h" |
19 #include "content/public/browser/render_frame_host.h" | 18 #include "content/public/browser/render_frame_host.h" |
20 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
| 20 #include "content/public/test/browser_test_utils.h" |
21 #include "content/public/test/test_utils.h" | 21 #include "content/public/test/test_utils.h" |
22 #include "extensions/browser/extension_registry.h" | 22 #include "extensions/browser/extension_registry.h" |
23 #include "extensions/common/switches.h" | 23 #include "extensions/common/switches.h" |
24 #include "extensions/test/extension_test_message_listener.h" | 24 #include "extensions/test/extension_test_message_listener.h" |
25 #include "extensions/test/result_catcher.h" | 25 #include "extensions/test/result_catcher.h" |
26 | 26 |
27 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
28 #include "base/win/windows_version.h" | 28 #include "base/win/windows_version.h" |
29 #endif | 29 #endif |
30 | 30 |
31 namespace extensions { | 31 namespace extensions { |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 const char kExtensionId[] = "ddchlicdkolnonkihahngkmmmjnjlkkf"; | 35 const char kExtensionId[] = "ddchlicdkolnonkihahngkmmmjnjlkkf"; |
36 | 36 |
37 class TabCaptureApiTest : public ExtensionApiTest { | 37 class TabCaptureApiTest : public ExtensionApiTest { |
38 public: | 38 public: |
39 void SetUpCommandLine(CommandLine* command_line) override { | 39 void SetUpCommandLine(CommandLine* command_line) override { |
40 ExtensionApiTest::SetUpCommandLine(command_line); | 40 ExtensionApiTest::SetUpCommandLine(command_line); |
41 // Specify smallish window size to make testing of tab capture less CPU | 41 // Specify smallish window size to make testing of tab capture less CPU |
42 // intensive. | 42 // intensive. |
43 command_line->AppendSwitchASCII(::switches::kWindowSize, "300,300"); | 43 command_line->AppendSwitchASCII(::switches::kWindowSize, "300,300"); |
44 } | 44 } |
45 | 45 |
46 void AddExtensionToCommandLineWhitelist() { | 46 void AddExtensionToCommandLineWhitelist() { |
47 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 47 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
48 switches::kWhitelistedExtensionID, kExtensionId); | 48 switches::kWhitelistedExtensionID, kExtensionId); |
49 } | 49 } |
| 50 |
| 51 protected: |
| 52 void SimulateMouseClickInCurrentTab() { |
| 53 content::SimulateMouseClick( |
| 54 browser()->tab_strip_model()->GetActiveWebContents(), |
| 55 0, |
| 56 blink::WebMouseEvent::ButtonLeft); |
| 57 } |
50 }; | 58 }; |
51 | 59 |
52 class TabCaptureApiPixelTest : public TabCaptureApiTest { | 60 class TabCaptureApiPixelTest : public TabCaptureApiTest { |
53 public: | 61 public: |
54 void SetUp() override { | 62 void SetUp() override { |
55 if (!IsTooIntensiveForThisPlatform()) | 63 if (!IsTooIntensiveForThisPlatform()) |
56 EnablePixelOutput(); | 64 EnablePixelOutput(); |
57 TabCaptureApiTest::SetUp(); | 65 TabCaptureApiTest::SetUp(); |
58 } | 66 } |
59 | 67 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 before_whitelist_extension.Reply(""); | 198 before_whitelist_extension.Reply(""); |
191 | 199 |
192 ResultCatcher catcher; | 200 ResultCatcher catcher; |
193 catcher.RestrictToBrowserContext(browser()->profile()); | 201 catcher.RestrictToBrowserContext(browser()->profile()); |
194 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 202 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
195 } | 203 } |
196 | 204 |
197 // http://crbug.com/177163 | 205 // http://crbug.com/177163 |
198 #if defined(OS_WIN) && !defined(NDEBUG) | 206 #if defined(OS_WIN) && !defined(NDEBUG) |
199 #define MAYBE_FullscreenEvents DISABLED_FullscreenEvents | 207 #define MAYBE_FullscreenEvents DISABLED_FullscreenEvents |
200 #elif defined(USE_AURA) || defined(OS_MACOSX) | |
201 // These don't always fire fullscreen events when run in tests. Tested manually. | |
202 #define MAYBE_FullscreenEvents DISABLED_FullscreenEvents | |
203 #elif defined(OS_LINUX) | |
204 // Flaky to get out of fullscreen in tests. Tested manually. | |
205 #define MAYBE_FullscreenEvents DISABLED_FullscreenEvents | |
206 #else | 208 #else |
207 #define MAYBE_FullscreenEvents FullscreenEvents | 209 #define MAYBE_FullscreenEvents FullscreenEvents |
208 #endif | 210 #endif |
| 211 // Tests that fullscreen transitions during a tab capture session dispatch |
| 212 // events to the onStatusChange listener. The test loads a page that toggles |
| 213 // fullscreen mode, using the Fullscreen Javascript API, in response to mouse |
| 214 // clicks. |
209 IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_FullscreenEvents) { | 215 IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_FullscreenEvents) { |
210 AddExtensionToCommandLineWhitelist(); | 216 AddExtensionToCommandLineWhitelist(); |
211 | 217 |
212 content::OpenURLParams params(GURL("chrome://version"), | 218 ExtensionTestMessageListener tab_capture_started("tab_capture_started", true); |
213 content::Referrer(), | 219 ExtensionTestMessageListener entered_fullscreen("entered_fullscreen", true); |
214 CURRENT_TAB, | |
215 ui::PAGE_TRANSITION_LINK, false); | |
216 content::WebContents* web_contents = browser()->OpenURL(params); | |
217 | |
218 ExtensionTestMessageListener listeners_setup("ready1", true); | |
219 ExtensionTestMessageListener fullscreen_entered("ready2", true); | |
220 | 220 |
221 ASSERT_TRUE(RunExtensionSubtest("tab_capture", "fullscreen_test.html")) | 221 ASSERT_TRUE(RunExtensionSubtest("tab_capture", "fullscreen_test.html")) |
222 << message_; | 222 << message_; |
223 EXPECT_TRUE(listeners_setup.WaitUntilSatisfied()); | 223 EXPECT_TRUE(tab_capture_started.WaitUntilSatisfied()); |
| 224 tab_capture_started.Reply(""); |
224 | 225 |
225 // Toggle fullscreen after setting up listeners. | 226 // Click on the page to trigger the Javascript that will toggle the tab into |
226 browser()->fullscreen_controller()->ToggleFullscreenModeForTab(web_contents, | 227 // fullscreen mode. |
227 true); | 228 SimulateMouseClickInCurrentTab(); |
228 listeners_setup.Reply(""); | 229 EXPECT_TRUE(entered_fullscreen.WaitUntilSatisfied()); |
| 230 entered_fullscreen.Reply(""); |
229 | 231 |
230 // Toggle again after JS should have the event. | 232 // Click again to exit fullscreen mode. |
231 EXPECT_TRUE(fullscreen_entered.WaitUntilSatisfied()); | 233 SimulateMouseClickInCurrentTab(); |
232 browser()->fullscreen_controller()->ToggleFullscreenModeForTab(web_contents, | |
233 false); | |
234 fullscreen_entered.Reply(""); | |
235 | 234 |
| 235 // Wait until the page examines its results and calls chrome.test.succeed(). |
236 ResultCatcher catcher; | 236 ResultCatcher catcher; |
237 catcher.RestrictToBrowserContext(browser()->profile()); | 237 catcher.RestrictToBrowserContext(browser()->profile()); |
238 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 238 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
239 } | 239 } |
240 | 240 |
241 // http://crbug.com/177163 | 241 // http://crbug.com/177163 |
242 #if defined(OS_WIN) && !defined(NDEBUG) | 242 #if defined(OS_WIN) && !defined(NDEBUG) |
243 #define MAYBE_GrantForChromePages DISABLED_GrantForChromePages | 243 #define MAYBE_GrantForChromePages DISABLED_GrantForChromePages |
244 #else | 244 #else |
245 #define MAYBE_GrantForChromePages GrantForChromePages | 245 #define MAYBE_GrantForChromePages GrantForChromePages |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 return; | 355 return; |
356 } | 356 } |
357 content::RunMessageLoop(); | 357 content::RunMessageLoop(); |
358 } | 358 } |
359 browser()->tab_strip_model()->RemoveObserver(&observer); | 359 browser()->tab_strip_model()->RemoveObserver(&observer); |
360 } | 360 } |
361 | 361 |
362 } // namespace | 362 } // namespace |
363 | 363 |
364 } // namespace extensions | 364 } // namespace extensions |
OLD | NEW |