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" |
29 #include "extensions/common/constants.h" | 30 #include "extensions/common/constants.h" |
30 | 31 |
31 using content::WebContents; | 32 using content::WebContents; |
32 using extensions::AppSorting; | 33 using extensions::AppSorting; |
33 using extensions::Extension; | 34 using extensions::Extension; |
34 | 35 |
35 class ExtensionInstallUIBrowserTest : public ExtensionBrowserTest { | 36 class ExtensionInstallUIBrowserTest : public ExtensionBrowserTest { |
36 public: | 37 public: |
| 38 ExtensionInstallUIBrowserTest() {} |
| 39 ~ExtensionInstallUIBrowserTest() override {} |
| 40 |
37 // Checks that a theme info bar is currently visible and issues an undo to | 41 // Checks that a theme info bar is currently visible and issues an undo to |
38 // revert to the previous theme. | 42 // revert to the previous theme. |
39 void VerifyThemeInfoBarAndUndoInstall() { | 43 void VerifyThemeInfoBarAndUndoInstall() { |
40 WebContents* web_contents = | 44 WebContents* web_contents = |
41 browser()->tab_strip_model()->GetActiveWebContents(); | 45 browser()->tab_strip_model()->GetActiveWebContents(); |
42 ASSERT_TRUE(web_contents); | 46 ASSERT_TRUE(web_contents); |
43 InfoBarService* infobar_service = | 47 InfoBarService* infobar_service = |
44 InfoBarService::FromWebContents(web_contents); | 48 InfoBarService::FromWebContents(web_contents); |
45 ASSERT_EQ(1U, infobar_service->infobar_count()); | 49 ASSERT_EQ(1U, infobar_service->infobar_count()); |
46 ConfirmInfoBarDelegate* delegate = | 50 ConfirmInfoBarDelegate* delegate = |
47 infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 51 infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
48 ASSERT_TRUE(delegate); | 52 ASSERT_TRUE(delegate); |
49 delegate->Cancel(); | 53 delegate->Cancel(); |
| 54 WaitForThemeChange(); |
50 ASSERT_EQ(0U, infobar_service->infobar_count()); | 55 ASSERT_EQ(0U, infobar_service->infobar_count()); |
51 } | 56 } |
52 | 57 |
53 // Install the given theme from the data dir and verify expected name. | 58 // Install the given theme from the data dir and verify expected name. |
54 void InstallThemeAndVerify(const char* theme_name, | 59 void InstallThemeAndVerify(const char* theme_name, |
55 const std::string& expected_name) { | 60 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; | |
59 const base::FilePath theme_path = test_data_dir_.AppendASCII(theme_name); | 61 const base::FilePath theme_path = test_data_dir_.AppendASCII(theme_name); |
60 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_path, expected_change, | 62 const bool theme_exists = GetTheme(); |
61 browser())); | 63 // Themes install asynchronously so we must check the number of enabled |
| 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 |
62 const Extension* theme = GetTheme(); | 77 const Extension* theme = GetTheme(); |
63 ASSERT_TRUE(theme); | 78 ASSERT_TRUE(theme); |
64 ASSERT_EQ(theme->name(), expected_name); | 79 ASSERT_EQ(theme->name(), expected_name); |
65 } | 80 } |
66 | 81 |
67 const Extension* GetTheme() const { | 82 const Extension* GetTheme() const { |
68 return ThemeServiceFactory::GetThemeForProfile(browser()->profile()); | 83 return ThemeServiceFactory::GetThemeForProfile(browser()->profile()); |
69 } | 84 } |
| 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); |
70 }; | 96 }; |
71 | 97 |
72 // Fails on Linux and Windows (http://crbug.com/580907). | 98 // Fails on Linux and Windows (http://crbug.com/580907). |
73 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, | 99 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, |
74 DISABLED_TestThemeInstallUndoResetsToDefault) { | 100 DISABLED_TestThemeInstallUndoResetsToDefault) { |
75 // Install theme once and undo to verify we go back to default theme. | 101 // Install theme once and undo to verify we go back to default theme. |
76 base::FilePath theme_crx = PackExtension(test_data_dir_.AppendASCII("theme")); | 102 base::FilePath theme_crx = PackExtension(test_data_dir_.AppendASCII("theme")); |
77 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 1, browser())); | 103 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 1, browser())); |
| 104 WaitForThemeChange(); |
78 const Extension* theme = GetTheme(); | 105 const Extension* theme = GetTheme(); |
79 ASSERT_TRUE(theme); | 106 ASSERT_TRUE(theme); |
80 std::string theme_id = theme->id(); | 107 std::string theme_id = theme->id(); |
81 VerifyThemeInfoBarAndUndoInstall(); | 108 VerifyThemeInfoBarAndUndoInstall(); |
82 ASSERT_EQ(NULL, GetTheme()); | 109 ASSERT_EQ(NULL, GetTheme()); |
83 | 110 |
84 // Set the same theme twice and undo to verify we go back to default theme. | 111 // Set the same theme twice and undo to verify we go back to default theme. |
85 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 0, browser())); | 112 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 0, browser())); |
| 113 WaitForThemeChange(); |
86 theme = GetTheme(); | 114 theme = GetTheme(); |
87 ASSERT_TRUE(theme); | 115 ASSERT_TRUE(theme); |
88 ASSERT_EQ(theme_id, theme->id()); | 116 ASSERT_EQ(theme_id, theme->id()); |
89 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 0, browser())); | 117 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 0, browser())); |
| 118 WaitForThemeChange(); |
90 theme = GetTheme(); | 119 theme = GetTheme(); |
91 ASSERT_TRUE(theme); | 120 ASSERT_TRUE(theme); |
92 ASSERT_EQ(theme_id, theme->id()); | 121 ASSERT_EQ(theme_id, theme->id()); |
93 VerifyThemeInfoBarAndUndoInstall(); | 122 VerifyThemeInfoBarAndUndoInstall(); |
94 ASSERT_EQ(NULL, GetTheme()); | 123 ASSERT_EQ(NULL, GetTheme()); |
95 } | 124 } |
96 | 125 |
97 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, | 126 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, |
98 TestThemeInstallUndoResetsToPreviousTheme) { | 127 TestThemeInstallUndoResetsToPreviousTheme) { |
99 // Install first theme. | 128 // Install first theme. |
100 InstallThemeAndVerify("theme", "camo theme"); | 129 InstallThemeAndVerify("theme", "camo theme"); |
101 const Extension* theme = GetTheme(); | 130 const Extension* theme = GetTheme(); |
102 std::string theme_id = theme->id(); | 131 std::string theme_id = theme->id(); |
103 | 132 |
104 // Then install second theme. | 133 // Then install second theme. |
105 InstallThemeAndVerify("theme2", "snowflake theme"); | 134 InstallThemeAndVerify("theme2", "snowflake theme"); |
106 const Extension* theme2 = GetTheme(); | 135 const Extension* theme2 = GetTheme(); |
107 EXPECT_FALSE(theme_id == theme2->id()); | 136 EXPECT_NE(theme_id, theme2->id()); |
108 | 137 |
109 // Undo second theme will revert to first theme. | 138 // Undo second theme will revert to first theme. |
110 VerifyThemeInfoBarAndUndoInstall(); | 139 VerifyThemeInfoBarAndUndoInstall(); |
111 EXPECT_EQ(theme, GetTheme()); | 140 EXPECT_EQ(theme, GetTheme()); |
112 } | 141 } |
113 | 142 |
114 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, | 143 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, |
115 TestThemeReset) { | 144 TestThemeReset) { |
116 InstallThemeAndVerify("theme", "camo theme"); | 145 InstallThemeAndVerify("theme", "camo theme"); |
117 | 146 |
118 // Reset to default theme. | 147 // Reset to default theme. |
119 ThemeServiceFactory::GetForProfile(browser()->profile())->UseDefaultTheme(); | 148 ThemeServiceFactory::GetForProfile(browser()->profile())->UseDefaultTheme(); |
120 ASSERT_FALSE(GetTheme()); | 149 ASSERT_FALSE(GetTheme()); |
121 } | 150 } |
122 | 151 |
123 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, | 152 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, |
124 TestInstallThemeInFullScreen) { | 153 TestInstallThemeInFullScreen) { |
125 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_FULLSCREEN)); | 154 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_FULLSCREEN)); |
126 InstallThemeAndVerify("theme", "camo theme"); | 155 InstallThemeAndVerify("theme", "camo theme"); |
127 } | 156 } |
OLD | NEW |