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