[email protected] | 1ee2f79 | 2011-02-07 13:22:35 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 9b6d31d | 2009-09-01 01:44:03 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/extensions/extension_apitest.h" |
| 6 | |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 7 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 8 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 2ad4a90 | 2010-11-17 06:05:13 | [diff] [blame] | 9 | #include "chrome/browser/ui/browser.h" |
[email protected] | 00070c73 | 2011-04-09 15:31:33 | [diff] [blame] | 10 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | dfd6ee45 | 2010-02-24 19:47:31 | [diff] [blame] | 11 | #include "chrome/common/pref_names.h" |
[email protected] | aace40c | 2011-02-15 17:10:21 | [diff] [blame] | 12 | #include "net/base/mock_host_resolver.h" |
[email protected] | dfd6ee45 | 2010-02-24 19:47:31 | [diff] [blame] | 13 | |
[email protected] | 3b20d019 | 2010-10-14 17:29:57 | [diff] [blame] | 14 | // Possible race in ChromeURLDataManager. http://crbug.com/59198 |
| 15 | #if defined(OS_MACOSX) || defined(OS_LINUX) |
[email protected] | a5eb2d67 | 2010-10-22 07:24:48 | [diff] [blame] | 16 | #define MAYBE_TabOnRemoved DISABLED_TabOnRemoved |
[email protected] | 3b20d019 | 2010-10-14 17:29:57 | [diff] [blame] | 17 | #else |
| 18 | #define MAYBE_TabOnRemoved TabOnRemoved |
| 19 | #endif |
| 20 | |
[email protected] | d479b8e2 | 2011-02-09 05:19:49 | [diff] [blame] | 21 | // Window resizes are not completed by the time the callback happens, |
| 22 | // so these tests fail on linux. http://crbug.com/72369 |
| 23 | #if defined(OS_LINUX) |
| 24 | #define MAYBE_FocusWindowDoesNotExitFullscreen \ |
| 25 | DISABLED_FocusWindowDoesNotExitFullscreen |
| 26 | #define MAYBE_UpdateWindowSizeExitsFullscreen \ |
| 27 | DISABLED_UpdateWindowSizeExitsFullscreen |
| 28 | #else |
| 29 | #define MAYBE_FocusWindowDoesNotExitFullscreen FocusWindowDoesNotExitFullscreen |
| 30 | #define MAYBE_UpdateWindowSizeExitsFullscreen UpdateWindowSizeExitsFullscreen |
| 31 | #endif |
| 32 | |
[email protected] | fab201a | 2011-06-07 00:52:49 | [diff] [blame] | 33 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Tabs) { |
[email protected] | c80580c7 | 2011-02-01 16:23:41 | [diff] [blame] | 34 | ASSERT_TRUE(StartTestServer()); |
[email protected] | dfd6ee45 | 2010-02-24 19:47:31 | [diff] [blame] | 35 | |
| 36 | // The test creates a tab and checks that the URL of the new tab |
| 37 | // is that of the new tab page. Make sure the pref that controls |
| 38 | // this is set. |
| 39 | browser()->profile()->GetPrefs()->SetBoolean( |
| 40 | prefs::kHomePageIsNewTabPage, true); |
| 41 | |
[email protected] | 9cc688d | 2010-11-01 06:18:32 | [diff] [blame] | 42 | ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crud.html")) << message_; |
| 43 | } |
| 44 | |
[email protected] | d059169 | 2011-06-07 23:52:48 | [diff] [blame^] | 45 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Tabs2) { |
| 46 | ASSERT_TRUE(StartTestServer()); |
| 47 | ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crud2.html")) << message_; |
| 48 | } |
| 49 | |
[email protected] | 4ce3988 | 2010-11-08 16:06:05 | [diff] [blame] | 50 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabPinned) { |
[email protected] | c80580c7 | 2011-02-01 16:23:41 | [diff] [blame] | 51 | ASSERT_TRUE(StartTestServer()); |
[email protected] | 4ce3988 | 2010-11-08 16:06:05 | [diff] [blame] | 52 | ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "pinned.html")) << message_; |
| 53 | } |
| 54 | |
[email protected] | 9cc688d | 2010-11-01 06:18:32 | [diff] [blame] | 55 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabMove) { |
[email protected] | c80580c7 | 2011-02-01 16:23:41 | [diff] [blame] | 56 | ASSERT_TRUE(StartTestServer()); |
[email protected] | 9cc688d | 2010-11-01 06:18:32 | [diff] [blame] | 57 | ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "move.html")) << message_; |
| 58 | } |
| 59 | |
| 60 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabEvents) { |
[email protected] | c80580c7 | 2011-02-01 16:23:41 | [diff] [blame] | 61 | ASSERT_TRUE(StartTestServer()); |
[email protected] | 9cc688d | 2010-11-01 06:18:32 | [diff] [blame] | 62 | ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "events.html")) << message_; |
| 63 | } |
| 64 | |
| 65 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabRelativeURLs) { |
[email protected] | c80580c7 | 2011-02-01 16:23:41 | [diff] [blame] | 66 | ASSERT_TRUE(StartTestServer()); |
[email protected] | 9cc688d | 2010-11-01 06:18:32 | [diff] [blame] | 67 | ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "relative_urls.html")) |
| 68 | << message_; |
[email protected] | 9b6d31d | 2009-09-01 01:44:03 | [diff] [blame] | 69 | } |
[email protected] | da9754b | 2010-04-01 14:56:19 | [diff] [blame] | 70 | |
[email protected] | d33a2239 | 2011-02-24 21:39:35 | [diff] [blame] | 71 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabCrashBrowser) { |
| 72 | ASSERT_TRUE(StartTestServer()); |
| 73 | ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crash.html")) << message_; |
| 74 | } |
| 75 | |
[email protected] | 89393438 | 2010-05-21 14:09:41 | [diff] [blame] | 76 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabGetCurrent) { |
[email protected] | 761e716 | 2010-10-18 19:26:39 | [diff] [blame] | 77 | ASSERT_TRUE(StartTestServer()); |
[email protected] | 89393438 | 2010-05-21 14:09:41 | [diff] [blame] | 78 | ASSERT_TRUE(RunExtensionTest("tabs/get_current")) << message_; |
| 79 | } |
[email protected] | e3eafb29 | 2010-04-14 21:30:41 | [diff] [blame] | 80 | |
[email protected] | 89393438 | 2010-05-21 14:09:41 | [diff] [blame] | 81 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabConnect) { |
[email protected] | 761e716 | 2010-10-18 19:26:39 | [diff] [blame] | 82 | ASSERT_TRUE(StartTestServer()); |
[email protected] | 89393438 | 2010-05-21 14:09:41 | [diff] [blame] | 83 | ASSERT_TRUE(RunExtensionTest("tabs/connect")) << message_; |
| 84 | } |
[email protected] | e3eafb29 | 2010-04-14 21:30:41 | [diff] [blame] | 85 | |
[email protected] | 3b20d019 | 2010-10-14 17:29:57 | [diff] [blame] | 86 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_TabOnRemoved) { |
[email protected] | 761e716 | 2010-10-18 19:26:39 | [diff] [blame] | 87 | ASSERT_TRUE(StartTestServer()); |
[email protected] | 89393438 | 2010-05-21 14:09:41 | [diff] [blame] | 88 | ASSERT_TRUE(RunExtensionTest("tabs/on_removed")) << message_; |
[email protected] | e3eafb29 | 2010-04-14 21:30:41 | [diff] [blame] | 89 | } |
| 90 | |
[email protected] | 3ebc22ea | 2011-05-26 06:38:05 | [diff] [blame] | 91 | // Test is timing out on linux and cros and flaky on others. |
| 92 | // See http://crbug.com/83876 |
| 93 | #if defined(OS_LINUX) |
[email protected] | e19bd2aa | 2011-05-26 02:13:43 | [diff] [blame] | 94 | #define MAYBE_CaptureVisibleTabJpeg DISABLED_CaptureVisibleTabJpeg |
| 95 | #else |
| 96 | #define MAYBE_CaptureVisibleTabJpeg FLAKY_CaptureVisibleTabJpeg |
| 97 | #endif |
| 98 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_CaptureVisibleTabJpeg) { |
[email protected] | aace40c | 2011-02-15 17:10:21 | [diff] [blame] | 99 | host_resolver()->AddRule("a.com", "127.0.0.1"); |
| 100 | host_resolver()->AddRule("b.com", "127.0.0.1"); |
[email protected] | 761e716 | 2010-10-18 19:26:39 | [diff] [blame] | 101 | ASSERT_TRUE(StartTestServer()); |
[email protected] | ff65139 | 2010-07-23 20:21:08 | [diff] [blame] | 102 | ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab", |
| 103 | "test_jpeg.html")) << message_; |
| 104 | } |
| 105 | |
[email protected] | 7d2f35ed | 2011-05-30 02:59:51 | [diff] [blame] | 106 | // Test is timing out on linux and cros and flaky on others. |
| 107 | // See http://crbug.com/83876 |
| 108 | #if defined(OS_LINUX) |
[email protected] | 3ebc22ea | 2011-05-26 06:38:05 | [diff] [blame] | 109 | #define MAYBE_CaptureVisibleTabPng DISABLED_CaptureVisibleTabPng |
| 110 | #else |
| 111 | #define MAYBE_CaptureVisibleTabPng FLAKY_CaptureVisibleTabPng |
| 112 | #endif |
| 113 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_CaptureVisibleTabPng) { |
[email protected] | aace40c | 2011-02-15 17:10:21 | [diff] [blame] | 114 | host_resolver()->AddRule("a.com", "127.0.0.1"); |
| 115 | host_resolver()->AddRule("b.com", "127.0.0.1"); |
[email protected] | 761e716 | 2010-10-18 19:26:39 | [diff] [blame] | 116 | ASSERT_TRUE(StartTestServer()); |
[email protected] | ff65139 | 2010-07-23 20:21:08 | [diff] [blame] | 117 | ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab", |
| 118 | "test_png.html")) << message_; |
[email protected] | da9754b | 2010-04-01 14:56:19 | [diff] [blame] | 119 | } |
[email protected] | 5f362e01 | 2010-05-19 20:26:25 | [diff] [blame] | 120 | |
[email protected] | 64a2b8ab | 2011-05-26 15:45:36 | [diff] [blame] | 121 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_CaptureVisibleTabRace) { |
[email protected] | 7181ce5 | 2011-04-21 18:47:36 | [diff] [blame] | 122 | ASSERT_TRUE(StartTestServer()); |
| 123 | ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab", |
| 124 | "test_race.html")) << message_; |
| 125 | } |
| 126 | |
| 127 | |
[email protected] | 5f362e01 | 2010-05-19 20:26:25 | [diff] [blame] | 128 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabsOnUpdated) { |
[email protected] | 761e716 | 2010-10-18 19:26:39 | [diff] [blame] | 129 | ASSERT_TRUE(StartTestServer()); |
[email protected] | 5f362e01 | 2010-05-19 20:26:25 | [diff] [blame] | 130 | ASSERT_TRUE(RunExtensionTest("tabs/on_updated")) << message_; |
| 131 | } |
[email protected] | 1ee2f79 | 2011-02-07 13:22:35 | [diff] [blame] | 132 | |
[email protected] | d479b8e2 | 2011-02-09 05:19:49 | [diff] [blame] | 133 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, |
| 134 | MAYBE_FocusWindowDoesNotExitFullscreen) { |
| 135 | browser()->window()->SetFullscreen(true); |
| 136 | bool is_fullscreen = browser()->window()->IsFullscreen(); |
| 137 | ASSERT_TRUE(RunExtensionTest("window_update/focus")) << message_; |
| 138 | ASSERT_EQ(is_fullscreen, browser()->window()->IsFullscreen()); |
| 139 | } |
| 140 | |
| 141 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, |
| 142 | MAYBE_UpdateWindowSizeExitsFullscreen) { |
| 143 | browser()->window()->SetFullscreen(true); |
| 144 | ASSERT_TRUE(RunExtensionTest("window_update/sizing")) << message_; |
| 145 | ASSERT_FALSE(browser()->window()->IsFullscreen()); |
| 146 | } |
| 147 | |
| 148 | #if defined(OS_WIN) |
| 149 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, FocusWindowDoesNotUnmaximize) { |
| 150 | gfx::NativeWindow window = browser()->window()->GetNativeHandle(); |
| 151 | ::SendMessage(window, WM_SYSCOMMAND, SC_MAXIMIZE, 0); |
| 152 | ASSERT_TRUE(RunExtensionTest("window_update/focus")) << message_; |
| 153 | ASSERT_TRUE(::IsZoomed(window)); |
| 154 | } |
| 155 | #endif // OS_WIN |
| 156 | |
[email protected] | 1ee2f79 | 2011-02-07 13:22:35 | [diff] [blame] | 157 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabledByPref) { |
| 158 | ASSERT_TRUE(StartTestServer()); |
| 159 | |
| 160 | browser()->profile()->GetPrefs()->SetBoolean(prefs::kIncognitoEnabled, false); |
| 161 | |
| 162 | // This makes sure that creating an incognito window fails due to pref |
| 163 | // (policy) being set. |
| 164 | ASSERT_TRUE(RunExtensionTest("tabs/incognito_disabled")) << message_; |
| 165 | } |
[email protected] | e524ff9 | 2011-03-30 13:26:58 | [diff] [blame] | 166 | |
| 167 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, GetViewsOfCreatedPopup) { |
| 168 | ASSERT_TRUE(StartTestServer()); |
| 169 | ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "get_views_popup.html")) |
| 170 | << message_; |
| 171 | } |
| 172 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, GetViewsOfCreatedWindow) { |
| 173 | ASSERT_TRUE(StartTestServer()); |
| 174 | ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "get_views_window.html")) |
| 175 | << message_; |
| 176 | } |