[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] | 2ba5f33b | 2010-11-02 20:36:23 | [diff] [blame] | 21 | // Crashes on linux views. http://crbug.com/61592 |
[email protected] | b8412996 | 2010-11-02 16:25:41 | [diff] [blame] | 22 | #if defined(OS_LINUX) && defined(TOOLKIT_VIEWS) |
[email protected] | 2ba5f33b | 2010-11-02 20:36:23 | [diff] [blame] | 23 | #define MAYBE_Tabs DISABLED_Tabs |
[email protected] | b8412996 | 2010-11-02 16:25:41 | [diff] [blame] | 24 | #else |
| 25 | #define MAYBE_Tabs Tabs |
| 26 | #endif |
| 27 | |
[email protected] | d479b8e2 | 2011-02-09 05:19:49 | [diff] [blame] | 28 | // Window resizes are not completed by the time the callback happens, |
| 29 | // so these tests fail on linux. http://crbug.com/72369 |
| 30 | #if defined(OS_LINUX) |
| 31 | #define MAYBE_FocusWindowDoesNotExitFullscreen \ |
| 32 | DISABLED_FocusWindowDoesNotExitFullscreen |
| 33 | #define MAYBE_UpdateWindowSizeExitsFullscreen \ |
| 34 | DISABLED_UpdateWindowSizeExitsFullscreen |
| 35 | #else |
| 36 | #define MAYBE_FocusWindowDoesNotExitFullscreen FocusWindowDoesNotExitFullscreen |
| 37 | #define MAYBE_UpdateWindowSizeExitsFullscreen UpdateWindowSizeExitsFullscreen |
| 38 | #endif |
| 39 | |
[email protected] | b8412996 | 2010-11-02 16:25:41 | [diff] [blame] | 40 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_Tabs) { |
[email protected] | c80580c7 | 2011-02-01 16:23:41 | [diff] [blame] | 41 | ASSERT_TRUE(StartTestServer()); |
[email protected] | dfd6ee45 | 2010-02-24 19:47:31 | [diff] [blame] | 42 | |
| 43 | // The test creates a tab and checks that the URL of the new tab |
| 44 | // is that of the new tab page. Make sure the pref that controls |
| 45 | // this is set. |
| 46 | browser()->profile()->GetPrefs()->SetBoolean( |
| 47 | prefs::kHomePageIsNewTabPage, true); |
| 48 | |
[email protected] | 9cc688d | 2010-11-01 06:18:32 | [diff] [blame] | 49 | ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crud.html")) << message_; |
| 50 | } |
| 51 | |
[email protected] | 4ce3988 | 2010-11-08 16:06:05 | [diff] [blame] | 52 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabPinned) { |
[email protected] | c80580c7 | 2011-02-01 16:23:41 | [diff] [blame] | 53 | ASSERT_TRUE(StartTestServer()); |
[email protected] | 4ce3988 | 2010-11-08 16:06:05 | [diff] [blame] | 54 | ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "pinned.html")) << message_; |
| 55 | } |
| 56 | |
[email protected] | 9cc688d | 2010-11-01 06:18:32 | [diff] [blame] | 57 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabMove) { |
[email protected] | c80580c7 | 2011-02-01 16:23:41 | [diff] [blame] | 58 | ASSERT_TRUE(StartTestServer()); |
[email protected] | 9cc688d | 2010-11-01 06:18:32 | [diff] [blame] | 59 | ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "move.html")) << message_; |
| 60 | } |
| 61 | |
| 62 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabEvents) { |
[email protected] | c80580c7 | 2011-02-01 16:23:41 | [diff] [blame] | 63 | ASSERT_TRUE(StartTestServer()); |
[email protected] | 9cc688d | 2010-11-01 06:18:32 | [diff] [blame] | 64 | ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "events.html")) << message_; |
| 65 | } |
| 66 | |
| 67 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabRelativeURLs) { |
[email protected] | c80580c7 | 2011-02-01 16:23:41 | [diff] [blame] | 68 | ASSERT_TRUE(StartTestServer()); |
[email protected] | 9cc688d | 2010-11-01 06:18:32 | [diff] [blame] | 69 | ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "relative_urls.html")) |
| 70 | << message_; |
[email protected] | 9b6d31d | 2009-09-01 01:44:03 | [diff] [blame] | 71 | } |
[email protected] | da9754b | 2010-04-01 14:56:19 | [diff] [blame] | 72 | |
[email protected] | d33a2239 | 2011-02-24 21:39:35 | [diff] [blame] | 73 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabCrashBrowser) { |
| 74 | ASSERT_TRUE(StartTestServer()); |
| 75 | ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crash.html")) << message_; |
| 76 | } |
| 77 | |
[email protected] | 89393438 | 2010-05-21 14:09:41 | [diff] [blame] | 78 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabGetCurrent) { |
[email protected] | 761e716 | 2010-10-18 19:26:39 | [diff] [blame] | 79 | ASSERT_TRUE(StartTestServer()); |
[email protected] | 89393438 | 2010-05-21 14:09:41 | [diff] [blame] | 80 | ASSERT_TRUE(RunExtensionTest("tabs/get_current")) << message_; |
| 81 | } |
[email protected] | e3eafb29 | 2010-04-14 21:30:41 | [diff] [blame] | 82 | |
[email protected] | 89393438 | 2010-05-21 14:09:41 | [diff] [blame] | 83 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabConnect) { |
[email protected] | 761e716 | 2010-10-18 19:26:39 | [diff] [blame] | 84 | ASSERT_TRUE(StartTestServer()); |
[email protected] | 89393438 | 2010-05-21 14:09:41 | [diff] [blame] | 85 | ASSERT_TRUE(RunExtensionTest("tabs/connect")) << message_; |
| 86 | } |
[email protected] | e3eafb29 | 2010-04-14 21:30:41 | [diff] [blame] | 87 | |
[email protected] | 3b20d019 | 2010-10-14 17:29:57 | [diff] [blame] | 88 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_TabOnRemoved) { |
[email protected] | 761e716 | 2010-10-18 19:26:39 | [diff] [blame] | 89 | ASSERT_TRUE(StartTestServer()); |
[email protected] | 89393438 | 2010-05-21 14:09:41 | [diff] [blame] | 90 | ASSERT_TRUE(RunExtensionTest("tabs/on_removed")) << message_; |
[email protected] | e3eafb29 | 2010-04-14 21:30:41 | [diff] [blame] | 91 | } |
| 92 | |
[email protected] | ff65139 | 2010-07-23 20:21:08 | [diff] [blame] | 93 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, CaptureVisibleTabJpeg) { |
[email protected] | aace40c | 2011-02-15 17:10:21 | [diff] [blame] | 94 | host_resolver()->AddRule("a.com", "127.0.0.1"); |
| 95 | host_resolver()->AddRule("b.com", "127.0.0.1"); |
[email protected] | 761e716 | 2010-10-18 19:26:39 | [diff] [blame] | 96 | ASSERT_TRUE(StartTestServer()); |
[email protected] | ff65139 | 2010-07-23 20:21:08 | [diff] [blame] | 97 | ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab", |
| 98 | "test_jpeg.html")) << message_; |
| 99 | } |
| 100 | |
[email protected] | 44aa9be | 2010-09-16 02:56:17 | [diff] [blame] | 101 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, CaptureVisibleTabPng) { |
[email protected] | aace40c | 2011-02-15 17:10:21 | [diff] [blame] | 102 | host_resolver()->AddRule("a.com", "127.0.0.1"); |
| 103 | host_resolver()->AddRule("b.com", "127.0.0.1"); |
[email protected] | 761e716 | 2010-10-18 19:26:39 | [diff] [blame] | 104 | ASSERT_TRUE(StartTestServer()); |
[email protected] | ff65139 | 2010-07-23 20:21:08 | [diff] [blame] | 105 | ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab", |
| 106 | "test_png.html")) << message_; |
[email protected] | da9754b | 2010-04-01 14:56:19 | [diff] [blame] | 107 | } |
[email protected] | 5f362e01 | 2010-05-19 20:26:25 | [diff] [blame] | 108 | |
| 109 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabsOnUpdated) { |
[email protected] | 761e716 | 2010-10-18 19:26:39 | [diff] [blame] | 110 | ASSERT_TRUE(StartTestServer()); |
[email protected] | 5f362e01 | 2010-05-19 20:26:25 | [diff] [blame] | 111 | ASSERT_TRUE(RunExtensionTest("tabs/on_updated")) << message_; |
| 112 | } |
[email protected] | 1ee2f79 | 2011-02-07 13:22:35 | [diff] [blame] | 113 | |
[email protected] | d479b8e2 | 2011-02-09 05:19:49 | [diff] [blame] | 114 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, |
| 115 | MAYBE_FocusWindowDoesNotExitFullscreen) { |
| 116 | browser()->window()->SetFullscreen(true); |
| 117 | bool is_fullscreen = browser()->window()->IsFullscreen(); |
| 118 | ASSERT_TRUE(RunExtensionTest("window_update/focus")) << message_; |
| 119 | ASSERT_EQ(is_fullscreen, browser()->window()->IsFullscreen()); |
| 120 | } |
| 121 | |
| 122 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, |
| 123 | MAYBE_UpdateWindowSizeExitsFullscreen) { |
| 124 | browser()->window()->SetFullscreen(true); |
| 125 | ASSERT_TRUE(RunExtensionTest("window_update/sizing")) << message_; |
| 126 | ASSERT_FALSE(browser()->window()->IsFullscreen()); |
| 127 | } |
| 128 | |
| 129 | #if defined(OS_WIN) |
| 130 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, FocusWindowDoesNotUnmaximize) { |
| 131 | gfx::NativeWindow window = browser()->window()->GetNativeHandle(); |
| 132 | ::SendMessage(window, WM_SYSCOMMAND, SC_MAXIMIZE, 0); |
| 133 | ASSERT_TRUE(RunExtensionTest("window_update/focus")) << message_; |
| 134 | ASSERT_TRUE(::IsZoomed(window)); |
| 135 | } |
| 136 | #endif // OS_WIN |
| 137 | |
[email protected] | 1ee2f79 | 2011-02-07 13:22:35 | [diff] [blame] | 138 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabledByPref) { |
| 139 | ASSERT_TRUE(StartTestServer()); |
| 140 | |
| 141 | browser()->profile()->GetPrefs()->SetBoolean(prefs::kIncognitoEnabled, false); |
| 142 | |
| 143 | // This makes sure that creating an incognito window fails due to pref |
| 144 | // (policy) being set. |
| 145 | ASSERT_TRUE(RunExtensionTest("tabs/incognito_disabled")) << message_; |
| 146 | } |
[email protected] | e524ff9 | 2011-03-30 13:26:58 | [diff] [blame] | 147 | |
| 148 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, GetViewsOfCreatedPopup) { |
| 149 | ASSERT_TRUE(StartTestServer()); |
| 150 | ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "get_views_popup.html")) |
| 151 | << message_; |
| 152 | } |
| 153 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, GetViewsOfCreatedWindow) { |
| 154 | ASSERT_TRUE(StartTestServer()); |
| 155 | ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "get_views_window.html")) |
| 156 | << message_; |
| 157 | } |