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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/extensions/extension_browsertest.h" | 11 #include "chrome/browser/extensions/extension_browsertest.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/infobars/infobar_service.h" | 13 #include "chrome/browser/infobars/infobar_service.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/themes/theme_service.h" | 15 #include "chrome/browser/themes/theme_service.h" |
16 #include "chrome/browser/themes/theme_service_factory.h" | 16 #include "chrome/browser/themes/theme_service_factory.h" |
17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_commands.h" | 18 #include "chrome/browser/ui/browser_commands.h" |
19 #include "chrome/browser/ui/browser_finder.h" | 19 #include "chrome/browser/ui/browser_finder.h" |
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
21 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
22 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
23 #include "components/crx_file/id_util.h" | 23 #include "components/crx_file/id_util.h" |
24 #include "components/infobars/core/confirm_infobar_delegate.h" | 24 #include "components/infobars/core/confirm_infobar_delegate.h" |
25 #include "components/infobars/core/infobar.h" | 25 #include "components/infobars/core/infobar.h" |
26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
27 #include "content/public/test/browser_test_utils.h" | 27 #include "content/public/test/browser_test_utils.h" |
28 #include "extensions/browser/app_sorting.h" | 28 #include "extensions/browser/app_sorting.h" |
29 #include "extensions/browser/extension_registry.h" | |
30 #include "extensions/common/constants.h" | 29 #include "extensions/common/constants.h" |
31 | 30 |
32 using content::WebContents; | 31 using content::WebContents; |
33 using extensions::AppSorting; | 32 using extensions::AppSorting; |
34 using extensions::Extension; | 33 using extensions::Extension; |
35 | 34 |
36 class ExtensionInstallUIBrowserTest : public ExtensionBrowserTest { | 35 class ExtensionInstallUIBrowserTest : public ExtensionBrowserTest { |
37 public: | 36 public: |
38 ExtensionInstallUIBrowserTest() {} | |
39 ~ExtensionInstallUIBrowserTest() override {} | |
40 | |
41 // Checks that a theme info bar is currently visible and issues an undo to | 37 // Checks that a theme info bar is currently visible and issues an undo to |
42 // revert to the previous theme. | 38 // revert to the previous theme. |
43 void VerifyThemeInfoBarAndUndoInstall() { | 39 void VerifyThemeInfoBarAndUndoInstall() { |
44 WebContents* web_contents = | 40 WebContents* web_contents = |
45 browser()->tab_strip_model()->GetActiveWebContents(); | 41 browser()->tab_strip_model()->GetActiveWebContents(); |
46 ASSERT_TRUE(web_contents); | 42 ASSERT_TRUE(web_contents); |
47 InfoBarService* infobar_service = | 43 InfoBarService* infobar_service = |
48 InfoBarService::FromWebContents(web_contents); | 44 InfoBarService::FromWebContents(web_contents); |
49 ASSERT_EQ(1U, infobar_service->infobar_count()); | 45 ASSERT_EQ(1U, infobar_service->infobar_count()); |
50 ConfirmInfoBarDelegate* delegate = | 46 ConfirmInfoBarDelegate* delegate = |
51 infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 47 infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
52 ASSERT_TRUE(delegate); | 48 ASSERT_TRUE(delegate); |
53 delegate->Cancel(); | 49 delegate->Cancel(); |
54 WaitForThemeChange(); | |
55 ASSERT_EQ(0U, infobar_service->infobar_count()); | 50 ASSERT_EQ(0U, infobar_service->infobar_count()); |
56 } | 51 } |
57 | 52 |
58 // Install the given theme from the data dir and verify expected name. | 53 // Install the given theme from the data dir and verify expected name. |
59 void InstallThemeAndVerify(const char* theme_name, | 54 void InstallThemeAndVerify(const char* theme_name, |
60 const std::string& expected_name) { | 55 const std::string& expected_name) { |
| 56 // If there is already a theme installed, the current theme should be |
| 57 // disabled and the new one installed + enabled. |
| 58 int expected_change = GetTheme() ? 0 : 1; |
61 const base::FilePath theme_path = test_data_dir_.AppendASCII(theme_name); | 59 const base::FilePath theme_path = test_data_dir_.AppendASCII(theme_name); |
62 const bool theme_exists = GetTheme(); | 60 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_path, expected_change, |
63 // Themes install asynchronously so we must check the number of enabled | 61 browser())); |
64 // extensions after theme install completes. | |
65 size_t num_before = extensions::ExtensionRegistry::Get(profile()) | |
66 ->enabled_extensions() | |
67 .size(); | |
68 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_path, 1, browser())); | |
69 WaitForThemeChange(); | |
70 size_t num_after = extensions::ExtensionRegistry::Get(profile()) | |
71 ->enabled_extensions() | |
72 .size(); | |
73 // If a theme was already installed, we're just swapping one for another, so | |
74 // no change in extension count. | |
75 EXPECT_EQ(num_before + (theme_exists ? 0 : 1), num_after); | |
76 | |
77 const Extension* theme = GetTheme(); | 62 const Extension* theme = GetTheme(); |
78 ASSERT_TRUE(theme); | 63 ASSERT_TRUE(theme); |
79 ASSERT_EQ(theme->name(), expected_name); | 64 ASSERT_EQ(theme->name(), expected_name); |
80 } | 65 } |
81 | 66 |
82 const Extension* GetTheme() const { | 67 const Extension* GetTheme() const { |
83 return ThemeServiceFactory::GetThemeForProfile(browser()->profile()); | 68 return ThemeServiceFactory::GetThemeForProfile(browser()->profile()); |
84 } | 69 } |
85 | |
86 void WaitForThemeChange() { | |
87 content::WindowedNotificationObserver theme_change_observer( | |
88 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | |
89 content::Source<ThemeService>( | |
90 ThemeServiceFactory::GetForProfile(browser()->profile()))); | |
91 theme_change_observer.Wait(); | |
92 } | |
93 | |
94 private: | |
95 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallUIBrowserTest); | |
96 }; | 70 }; |
97 | 71 |
98 // Fails on Linux and Windows (http://crbug.com/580907). | 72 // Fails on Linux and Windows (http://crbug.com/580907). |
99 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, | 73 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, |
100 DISABLED_TestThemeInstallUndoResetsToDefault) { | 74 DISABLED_TestThemeInstallUndoResetsToDefault) { |
101 // Install theme once and undo to verify we go back to default theme. | 75 // Install theme once and undo to verify we go back to default theme. |
102 base::FilePath theme_crx = PackExtension(test_data_dir_.AppendASCII("theme")); | 76 base::FilePath theme_crx = PackExtension(test_data_dir_.AppendASCII("theme")); |
103 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 1, browser())); | 77 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 1, browser())); |
104 WaitForThemeChange(); | |
105 const Extension* theme = GetTheme(); | 78 const Extension* theme = GetTheme(); |
106 ASSERT_TRUE(theme); | 79 ASSERT_TRUE(theme); |
107 std::string theme_id = theme->id(); | 80 std::string theme_id = theme->id(); |
108 VerifyThemeInfoBarAndUndoInstall(); | 81 VerifyThemeInfoBarAndUndoInstall(); |
109 ASSERT_EQ(NULL, GetTheme()); | 82 ASSERT_EQ(NULL, GetTheme()); |
110 | 83 |
111 // Set the same theme twice and undo to verify we go back to default theme. | 84 // Set the same theme twice and undo to verify we go back to default theme. |
112 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 0, browser())); | 85 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 0, browser())); |
113 WaitForThemeChange(); | |
114 theme = GetTheme(); | 86 theme = GetTheme(); |
115 ASSERT_TRUE(theme); | 87 ASSERT_TRUE(theme); |
116 ASSERT_EQ(theme_id, theme->id()); | 88 ASSERT_EQ(theme_id, theme->id()); |
117 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 0, browser())); | 89 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 0, browser())); |
118 WaitForThemeChange(); | |
119 theme = GetTheme(); | 90 theme = GetTheme(); |
120 ASSERT_TRUE(theme); | 91 ASSERT_TRUE(theme); |
121 ASSERT_EQ(theme_id, theme->id()); | 92 ASSERT_EQ(theme_id, theme->id()); |
122 VerifyThemeInfoBarAndUndoInstall(); | 93 VerifyThemeInfoBarAndUndoInstall(); |
123 ASSERT_EQ(NULL, GetTheme()); | 94 ASSERT_EQ(NULL, GetTheme()); |
124 } | 95 } |
125 | 96 |
126 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, | 97 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, |
127 TestThemeInstallUndoResetsToPreviousTheme) { | 98 TestThemeInstallUndoResetsToPreviousTheme) { |
128 // Install first theme. | 99 // Install first theme. |
129 InstallThemeAndVerify("theme", "camo theme"); | 100 InstallThemeAndVerify("theme", "camo theme"); |
130 const Extension* theme = GetTheme(); | 101 const Extension* theme = GetTheme(); |
131 std::string theme_id = theme->id(); | 102 std::string theme_id = theme->id(); |
132 | 103 |
133 // Then install second theme. | 104 // Then install second theme. |
134 InstallThemeAndVerify("theme2", "snowflake theme"); | 105 InstallThemeAndVerify("theme2", "snowflake theme"); |
135 const Extension* theme2 = GetTheme(); | 106 const Extension* theme2 = GetTheme(); |
136 EXPECT_NE(theme_id, theme2->id()); | 107 EXPECT_FALSE(theme_id == theme2->id()); |
137 | 108 |
138 // Undo second theme will revert to first theme. | 109 // Undo second theme will revert to first theme. |
139 VerifyThemeInfoBarAndUndoInstall(); | 110 VerifyThemeInfoBarAndUndoInstall(); |
140 EXPECT_EQ(theme, GetTheme()); | 111 EXPECT_EQ(theme, GetTheme()); |
141 } | 112 } |
142 | 113 |
143 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, | 114 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, |
144 TestThemeReset) { | 115 TestThemeReset) { |
145 InstallThemeAndVerify("theme", "camo theme"); | 116 InstallThemeAndVerify("theme", "camo theme"); |
146 | 117 |
147 // Reset to default theme. | 118 // Reset to default theme. |
148 ThemeServiceFactory::GetForProfile(browser()->profile())->UseDefaultTheme(); | 119 ThemeServiceFactory::GetForProfile(browser()->profile())->UseDefaultTheme(); |
149 ASSERT_FALSE(GetTheme()); | 120 ASSERT_FALSE(GetTheme()); |
150 } | 121 } |
151 | 122 |
152 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, | 123 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, |
153 TestInstallThemeInFullScreen) { | 124 TestInstallThemeInFullScreen) { |
154 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_FULLSCREEN)); | 125 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_FULLSCREEN)); |
155 InstallThemeAndVerify("theme", "camo theme"); | 126 InstallThemeAndVerify("theme", "camo theme"); |
156 } | 127 } |
OLD | NEW |