OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/strings/string_util.h" | 6 #include "base/strings/string_util.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/extensions/dev_mode_bubble_controller.h" | 8 #include "chrome/browser/extensions/dev_mode_bubble_controller.h" |
9 #include "chrome/browser/extensions/extension_function_test_utils.h" | 9 #include "chrome/browser/extensions/extension_function_test_utils.h" |
10 #include "chrome/browser/extensions/extension_message_bubble.h" | 10 #include "chrome/browser/extensions/extension_message_bubble.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/settings_api_bubble_controller.h" |
12 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h" | 13 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h" |
13 #include "chrome/browser/extensions/test_extension_system.h" | 14 #include "chrome/browser/extensions/test_extension_system.h" |
14 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
15 #include "content/public/test/test_browser_thread_bundle.h" | 16 #include "content/public/test/test_browser_thread_bundle.h" |
16 #include "extensions/common/extension.h" | 17 #include "extensions/common/extension.h" |
| 18 #include "extensions/common/extension_builder.h" |
17 #include "extensions/common/feature_switch.h" | 19 #include "extensions/common/feature_switch.h" |
18 | 20 |
| 21 namespace { |
| 22 |
| 23 const char kId1[] = "iccfkkhkfiphcjdakkmcjmkfboccmndk"; |
| 24 const char kId2[] = "ajjhifimiemdpmophmkkkcijegphclbl"; |
| 25 const char kId3[] = "ioibbbfddncmmabjmpokikkeiofalaek"; |
| 26 |
| 27 } // namespace |
| 28 |
19 namespace extensions { | 29 namespace extensions { |
20 | 30 |
21 class TestDelegate { | 31 class TestDelegate { |
22 public: | 32 public: |
23 TestDelegate() | 33 TestDelegate() |
24 : action_button_callback_count_(0), | 34 : action_button_callback_count_(0), |
25 dismiss_button_callback_count_(0), | 35 dismiss_button_callback_count_(0), |
26 link_click_callback_count_(0) { | 36 link_click_callback_count_(0) { |
27 } | 37 } |
28 | 38 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 ++dismiss_button_callback_count_; | 100 ++dismiss_button_callback_count_; |
91 DevModeBubbleController::OnBubbleDismiss(); | 101 DevModeBubbleController::OnBubbleDismiss(); |
92 } | 102 } |
93 | 103 |
94 virtual void OnLinkClicked() OVERRIDE { | 104 virtual void OnLinkClicked() OVERRIDE { |
95 ++link_click_callback_count_; | 105 ++link_click_callback_count_; |
96 DevModeBubbleController::OnLinkClicked(); | 106 DevModeBubbleController::OnLinkClicked(); |
97 } | 107 } |
98 }; | 108 }; |
99 | 109 |
| 110 // A test class for the SettingsApiBubbleController. |
| 111 class TestSettingsApiBubbleController : public SettingsApiBubbleController, |
| 112 public TestDelegate { |
| 113 public: |
| 114 TestSettingsApiBubbleController(Profile* profile, |
| 115 SettingsApiOverrideType type) |
| 116 : SettingsApiBubbleController(profile, type) {} |
| 117 |
| 118 virtual void OnBubbleAction() OVERRIDE { |
| 119 ++action_button_callback_count_; |
| 120 SettingsApiBubbleController::OnBubbleAction(); |
| 121 } |
| 122 |
| 123 virtual void OnBubbleDismiss() OVERRIDE { |
| 124 ++dismiss_button_callback_count_; |
| 125 SettingsApiBubbleController::OnBubbleDismiss(); |
| 126 } |
| 127 |
| 128 virtual void OnLinkClicked() OVERRIDE { |
| 129 ++link_click_callback_count_; |
| 130 SettingsApiBubbleController::OnLinkClicked(); |
| 131 } |
| 132 }; |
| 133 |
100 // A fake bubble used for testing the controller. Takes an action that specifies | 134 // A fake bubble used for testing the controller. Takes an action that specifies |
101 // what should happen when the bubble is "shown" (the bubble is actually not | 135 // what should happen when the bubble is "shown" (the bubble is actually not |
102 // shown, the corresponding action is taken immediately). | 136 // shown, the corresponding action is taken immediately). |
103 class FakeExtensionMessageBubble : public ExtensionMessageBubble { | 137 class FakeExtensionMessageBubble : public ExtensionMessageBubble { |
104 public: | 138 public: |
105 enum ExtensionBubbleAction { | 139 enum ExtensionBubbleAction { |
106 BUBBLE_ACTION_CLICK_ACTION_BUTTON = 0, | 140 BUBBLE_ACTION_CLICK_ACTION_BUTTON = 0, |
107 BUBBLE_ACTION_CLICK_DISMISS_BUTTON, | 141 BUBBLE_ACTION_CLICK_DISMISS_BUTTON, |
108 BUBBLE_ACTION_CLICK_LINK, | 142 BUBBLE_ACTION_CLICK_LINK, |
109 }; | 143 }; |
(...skipping 28 matching lines...) Expand all Loading... |
138 private: | 172 private: |
139 ExtensionBubbleAction action_; | 173 ExtensionBubbleAction action_; |
140 | 174 |
141 base::Closure action_callback_; | 175 base::Closure action_callback_; |
142 base::Closure dismiss_callback_; | 176 base::Closure dismiss_callback_; |
143 base::Closure link_callback_; | 177 base::Closure link_callback_; |
144 }; | 178 }; |
145 | 179 |
146 class ExtensionMessageBubbleTest : public testing::Test { | 180 class ExtensionMessageBubbleTest : public testing::Test { |
147 public: | 181 public: |
148 ExtensionMessageBubbleTest() { | 182 ExtensionMessageBubbleTest() {} |
| 183 |
| 184 void LoadGenericExtension(const std::string& index, |
| 185 const std::string& id, |
| 186 Manifest::Location location) { |
| 187 extensions::ExtensionBuilder builder; |
| 188 builder.SetManifest(extensions::DictionaryBuilder() |
| 189 .Set("name", std::string("Extension " + index)) |
| 190 .Set("version", "1.0") |
| 191 .Set("manifest_version", 2)); |
| 192 builder.SetLocation(location); |
| 193 builder.SetID(id); |
| 194 service_->AddExtension(builder.Build().get()); |
| 195 } |
| 196 |
| 197 void LoadExtensionWithAction(const std::string& index, |
| 198 const std::string& id, |
| 199 Manifest::Location location) { |
| 200 extensions::ExtensionBuilder builder; |
| 201 builder.SetManifest(extensions::DictionaryBuilder() |
| 202 .Set("name", std::string("Extension " + index)) |
| 203 .Set("version", "1.0") |
| 204 .Set("manifest_version", 2) |
| 205 .Set("browser_action", |
| 206 extensions::DictionaryBuilder().Set( |
| 207 "default_title", "Default title"))); |
| 208 builder.SetLocation(location); |
| 209 builder.SetID(id); |
| 210 service_->AddExtension(builder.Build().get()); |
| 211 } |
| 212 |
| 213 void LoadExtensionOverridingHome(const std::string& index, |
| 214 const std::string& id, |
| 215 Manifest::Location location) { |
| 216 extensions::ExtensionBuilder builder; |
| 217 builder.SetManifest(extensions::DictionaryBuilder() |
| 218 .Set("name", std::string("Extension " + index)) |
| 219 .Set("version", "1.0") |
| 220 .Set("manifest_version", 2) |
| 221 .Set("chrome_settings_overrides", |
| 222 extensions::DictionaryBuilder().Set( |
| 223 "homepage", "http://www.google.com"))); |
| 224 builder.SetLocation(location); |
| 225 builder.SetID(id); |
| 226 service_->AddExtension(builder.Build().get()); |
| 227 } |
| 228 |
| 229 void LoadExtensionOverridingStart(const std::string& index, |
| 230 const std::string& id, |
| 231 Manifest::Location location) { |
| 232 extensions::ExtensionBuilder builder; |
| 233 builder.SetManifest(extensions::DictionaryBuilder() |
| 234 .Set("name", std::string("Extension " + index)) |
| 235 .Set("version", "1.0") |
| 236 .Set("manifest_version", 2) |
| 237 .Set("chrome_settings_overrides", |
| 238 extensions::DictionaryBuilder().Set( |
| 239 "startup_pages", |
| 240 extensions::ListBuilder().Append( |
| 241 "http://www.google.com")))); |
| 242 builder.SetLocation(location); |
| 243 builder.SetID(id); |
| 244 service_->AddExtension(builder.Build().get()); |
| 245 } |
| 246 |
| 247 void Init() { |
149 // The two lines of magical incantation required to get the extension | 248 // The two lines of magical incantation required to get the extension |
150 // service to work inside a unit test and access the extension prefs. | 249 // service to work inside a unit test and access the extension prefs. |
151 thread_bundle_.reset(new content::TestBrowserThreadBundle); | 250 thread_bundle_.reset(new content::TestBrowserThreadBundle); |
152 profile_.reset(new TestingProfile); | 251 profile_.reset(new TestingProfile); |
153 | |
154 static_cast<TestExtensionSystem*>( | 252 static_cast<TestExtensionSystem*>( |
155 ExtensionSystem::Get(profile()))->CreateExtensionService( | 253 ExtensionSystem::Get(profile()))->CreateExtensionService( |
156 CommandLine::ForCurrentProcess(), | 254 CommandLine::ForCurrentProcess(), |
157 base::FilePath(), | 255 base::FilePath(), |
158 false); | 256 false); |
159 service_ = profile_->GetExtensionService(); | 257 service_ = profile_->GetExtensionService(); |
160 service_->Init(); | 258 service_->Init(); |
| 259 } |
161 | 260 |
162 std::string basic_extension = | |
163 "{\"name\": \"Extension #\"," | |
164 "\"version\": \"1.0\"," | |
165 "\"manifest_version\": 2}"; | |
166 std::string basic_extension_with_action = | |
167 "{\"name\": \"Extension #\"," | |
168 "\"version\": \"1.0\"," | |
169 "\"browser_action\": {" | |
170 " \"default_title\": \"Default title\"" | |
171 "}," | |
172 "\"manifest_version\": 2}"; | |
173 | |
174 std::string extension_data; | |
175 base::ReplaceChars(basic_extension_with_action, "#", "1", &extension_data); | |
176 scoped_refptr<Extension> my_test_extension1( | |
177 CreateExtension( | |
178 Manifest::COMMAND_LINE, | |
179 extension_data, | |
180 "Autogenerated 1")); | |
181 | |
182 base::ReplaceChars(basic_extension, "#", "2", &extension_data); | |
183 scoped_refptr<Extension> my_test_extension2( | |
184 CreateExtension( | |
185 Manifest::UNPACKED, | |
186 extension_data, | |
187 "Autogenerated 2")); | |
188 | |
189 base::ReplaceChars(basic_extension, "#", "3", &extension_data); | |
190 scoped_refptr<Extension> regular_extension( | |
191 CreateExtension( | |
192 Manifest::EXTERNAL_POLICY, | |
193 extension_data, | |
194 "Autogenerated 3")); | |
195 | |
196 extension_id1_ = my_test_extension1->id(); | |
197 extension_id2_ = my_test_extension2->id(); | |
198 extension_id3_ = regular_extension->id(); | |
199 | |
200 service_->AddExtension(regular_extension); | |
201 service_->AddExtension(my_test_extension1); | |
202 service_->AddExtension(my_test_extension2); | |
203 } | |
204 virtual ~ExtensionMessageBubbleTest() { | 261 virtual ~ExtensionMessageBubbleTest() { |
205 // Make sure the profile is destroyed before the thread bundle. | 262 // Make sure the profile is destroyed before the thread bundle. |
206 profile_.reset(NULL); | 263 profile_.reset(NULL); |
207 } | 264 } |
208 | 265 |
209 virtual void SetUp() { | 266 virtual void SetUp() { |
210 command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM)); | 267 command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM)); |
211 } | 268 } |
212 | 269 |
213 protected: | 270 protected: |
214 Profile* profile() { return profile_.get(); } | 271 Profile* profile() { return profile_.get(); } |
215 | 272 |
216 scoped_refptr<Extension> CreateExtension( | 273 scoped_refptr<Extension> CreateExtension( |
217 Manifest::Location location, | 274 Manifest::Location location, |
218 const std::string& data, | 275 const std::string& data, |
219 const std::string& id) { | 276 const std::string& id) { |
220 scoped_ptr<base::DictionaryValue> parsed_manifest( | 277 scoped_ptr<base::DictionaryValue> parsed_manifest( |
221 extension_function_test_utils::ParseDictionary(data)); | 278 extension_function_test_utils::ParseDictionary(data)); |
222 return extension_function_test_utils::CreateExtension( | 279 return extension_function_test_utils::CreateExtension( |
223 location, | 280 location, |
224 parsed_manifest.get(), | 281 parsed_manifest.get(), |
225 id); | 282 id); |
226 } | 283 } |
227 | 284 |
228 ExtensionService* service_; | 285 ExtensionService* service_; |
229 std::string extension_id1_; | |
230 std::string extension_id2_; | |
231 std::string extension_id3_; | |
232 | 286 |
233 private: | 287 private: |
234 scoped_ptr<CommandLine> command_line_; | 288 scoped_ptr<CommandLine> command_line_; |
235 scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_; | 289 scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_; |
236 scoped_ptr<TestingProfile> profile_; | 290 scoped_ptr<TestingProfile> profile_; |
237 | 291 |
238 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleTest); | 292 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleTest); |
239 }; | 293 }; |
240 | 294 |
241 // The feature this is meant to test is only implemented on Windows. | 295 // The feature this is meant to test is only implemented on Windows. |
242 #if defined(OS_WIN) | 296 #if defined(OS_WIN) |
243 #define MAYBE_WipeoutControllerTest WipeoutControllerTest | 297 #define MAYBE_WipeoutControllerTest WipeoutControllerTest |
244 #else | 298 #else |
245 #define MAYBE_WipeoutControllerTest DISABLED_WipeoutControllerTest | 299 #define MAYBE_WipeoutControllerTest DISABLED_WipeoutControllerTest |
246 #endif | 300 #endif |
247 | 301 |
248 TEST_F(ExtensionMessageBubbleTest, MAYBE_WipeoutControllerTest) { | 302 TEST_F(ExtensionMessageBubbleTest, MAYBE_WipeoutControllerTest) { |
249 // The test base class adds three extensions, and we control two of them in | 303 Init(); |
250 // this test (ids are: extension_id1_ and extension_id2_). | 304 // Add three extensions, and control two of them in this test (extension 1 |
| 305 // and 2). |
| 306 LoadExtensionWithAction("1", kId1, Manifest::COMMAND_LINE); |
| 307 LoadGenericExtension("2", kId2, Manifest::UNPACKED); |
| 308 LoadGenericExtension("3", kId3, Manifest::EXTERNAL_POLICY); |
| 309 |
251 scoped_ptr<TestSuspiciousExtensionBubbleController> controller( | 310 scoped_ptr<TestSuspiciousExtensionBubbleController> controller( |
252 new TestSuspiciousExtensionBubbleController(profile())); | 311 new TestSuspiciousExtensionBubbleController(profile())); |
253 FakeExtensionMessageBubble bubble; | 312 FakeExtensionMessageBubble bubble; |
254 bubble.set_action_on_show( | 313 bubble.set_action_on_show( |
255 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); | 314 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); |
256 | 315 |
257 // Validate that we don't have a suppress value for the extensions. | 316 // Validate that we don't have a suppress value for the extensions. |
258 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); | 317 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
259 EXPECT_FALSE(prefs->HasWipeoutBeenAcknowledged(extension_id1_)); | 318 EXPECT_FALSE(prefs->HasWipeoutBeenAcknowledged(kId1)); |
260 EXPECT_FALSE(prefs->HasWipeoutBeenAcknowledged(extension_id2_)); | 319 EXPECT_FALSE(prefs->HasWipeoutBeenAcknowledged(kId2)); |
261 | 320 |
262 EXPECT_FALSE(controller->ShouldShow()); | 321 EXPECT_FALSE(controller->ShouldShow()); |
263 std::vector<base::string16> suspicious_extensions = | 322 std::vector<base::string16> suspicious_extensions = |
264 controller->GetExtensionList(); | 323 controller->GetExtensionList(); |
265 EXPECT_EQ(0U, suspicious_extensions.size()); | 324 EXPECT_EQ(0U, suspicious_extensions.size()); |
266 EXPECT_EQ(0U, controller->link_click_count()); | 325 EXPECT_EQ(0U, controller->link_click_count()); |
267 EXPECT_EQ(0U, controller->dismiss_click_count()); | 326 EXPECT_EQ(0U, controller->dismiss_click_count()); |
268 | 327 |
269 // Now disable an extension, specifying the wipeout flag. | 328 // Now disable an extension, specifying the wipeout flag. |
270 service_->DisableExtension(extension_id1_, | 329 service_->DisableExtension(kId1, Extension::DISABLE_NOT_VERIFIED); |
271 Extension::DISABLE_NOT_VERIFIED); | |
272 | 330 |
273 EXPECT_FALSE(prefs->HasWipeoutBeenAcknowledged(extension_id1_)); | 331 EXPECT_FALSE(prefs->HasWipeoutBeenAcknowledged(kId1)); |
274 EXPECT_FALSE(prefs->HasWipeoutBeenAcknowledged(extension_id2_)); | 332 EXPECT_FALSE(prefs->HasWipeoutBeenAcknowledged(kId2)); |
275 controller.reset(new TestSuspiciousExtensionBubbleController( | 333 controller.reset(new TestSuspiciousExtensionBubbleController( |
276 profile())); | 334 profile())); |
277 SuspiciousExtensionBubbleController::ClearProfileListForTesting(); | 335 SuspiciousExtensionBubbleController::ClearProfileListForTesting(); |
278 EXPECT_TRUE(controller->ShouldShow()); | 336 EXPECT_TRUE(controller->ShouldShow()); |
279 suspicious_extensions = controller->GetExtensionList(); | 337 suspicious_extensions = controller->GetExtensionList(); |
280 ASSERT_EQ(1U, suspicious_extensions.size()); | 338 ASSERT_EQ(1U, suspicious_extensions.size()); |
281 EXPECT_TRUE(base::ASCIIToUTF16("Extension 1") == suspicious_extensions[0]); | 339 EXPECT_TRUE(base::ASCIIToUTF16("Extension 1") == suspicious_extensions[0]); |
282 controller->Show(&bubble); // Simulate showing the bubble. | 340 controller->Show(&bubble); // Simulate showing the bubble. |
283 EXPECT_EQ(0U, controller->link_click_count()); | 341 EXPECT_EQ(0U, controller->link_click_count()); |
284 EXPECT_EQ(1U, controller->dismiss_click_count()); | 342 EXPECT_EQ(1U, controller->dismiss_click_count()); |
285 // Now the acknowledge flag should be set only for the first extension. | 343 // Now the acknowledge flag should be set only for the first extension. |
286 EXPECT_TRUE(prefs->HasWipeoutBeenAcknowledged(extension_id1_)); | 344 EXPECT_TRUE(prefs->HasWipeoutBeenAcknowledged(kId1)); |
287 EXPECT_FALSE(prefs->HasWipeoutBeenAcknowledged(extension_id2_)); | 345 EXPECT_FALSE(prefs->HasWipeoutBeenAcknowledged(kId2)); |
288 // Clear the flag. | 346 // Clear the flag. |
289 prefs->SetWipeoutAcknowledged(extension_id1_, false); | 347 prefs->SetWipeoutAcknowledged(kId1, false); |
290 EXPECT_FALSE(prefs->HasWipeoutBeenAcknowledged(extension_id1_)); | 348 EXPECT_FALSE(prefs->HasWipeoutBeenAcknowledged(kId1)); |
291 | 349 |
292 // Now disable the other extension and exercise the link click code path. | 350 // Now disable the other extension and exercise the link click code path. |
293 service_->DisableExtension(extension_id2_, | 351 service_->DisableExtension(kId2, Extension::DISABLE_NOT_VERIFIED); |
294 Extension::DISABLE_NOT_VERIFIED); | |
295 | 352 |
296 bubble.set_action_on_show( | 353 bubble.set_action_on_show( |
297 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); | 354 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); |
298 controller.reset(new TestSuspiciousExtensionBubbleController( | 355 controller.reset(new TestSuspiciousExtensionBubbleController( |
299 profile())); | 356 profile())); |
300 SuspiciousExtensionBubbleController::ClearProfileListForTesting(); | 357 SuspiciousExtensionBubbleController::ClearProfileListForTesting(); |
301 EXPECT_TRUE(controller->ShouldShow()); | 358 EXPECT_TRUE(controller->ShouldShow()); |
302 suspicious_extensions = controller->GetExtensionList(); | 359 suspicious_extensions = controller->GetExtensionList(); |
303 ASSERT_EQ(2U, suspicious_extensions.size()); | 360 ASSERT_EQ(2U, suspicious_extensions.size()); |
304 EXPECT_TRUE(base::ASCIIToUTF16("Extension 1") == suspicious_extensions[1]); | 361 EXPECT_TRUE(base::ASCIIToUTF16("Extension 1") == suspicious_extensions[1]); |
305 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") == suspicious_extensions[0]); | 362 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") == suspicious_extensions[0]); |
306 controller->Show(&bubble); // Simulate showing the bubble. | 363 controller->Show(&bubble); // Simulate showing the bubble. |
307 EXPECT_EQ(1U, controller->link_click_count()); | 364 EXPECT_EQ(1U, controller->link_click_count()); |
308 EXPECT_EQ(0U, controller->dismiss_click_count()); | 365 EXPECT_EQ(0U, controller->dismiss_click_count()); |
309 EXPECT_TRUE(prefs->HasWipeoutBeenAcknowledged(extension_id1_)); | 366 EXPECT_TRUE(prefs->HasWipeoutBeenAcknowledged(kId1)); |
310 } | 367 } |
311 | 368 |
312 // The feature this is meant to test is only implemented on Windows. | 369 // The feature this is meant to test is only implemented on Windows. |
313 #if defined(OS_WIN) | 370 #if defined(OS_WIN) |
314 #define MAYBE_DevModeControllerTest DevModeControllerTest | 371 #define MAYBE_DevModeControllerTest DevModeControllerTest |
315 #else | 372 #else |
316 #define MAYBE_DevModeControllerTest DISABLED_DevModeControllerTest | 373 #define MAYBE_DevModeControllerTest DISABLED_DevModeControllerTest |
317 #endif | 374 #endif |
318 | 375 |
319 TEST_F(ExtensionMessageBubbleTest, MAYBE_DevModeControllerTest) { | 376 TEST_F(ExtensionMessageBubbleTest, MAYBE_DevModeControllerTest) { |
320 FeatureSwitch::ScopedOverride force_dev_mode_highlighting( | 377 FeatureSwitch::ScopedOverride force_dev_mode_highlighting( |
321 FeatureSwitch::force_dev_mode_highlighting(), true); | 378 FeatureSwitch::force_dev_mode_highlighting(), true); |
322 // The test base class adds three extensions, and we control two of them in | 379 Init(); |
323 // this test (ids are: extension_id1_ and extension_id2_). Extension 1 is a | 380 // Add three extensions, and control two of them in this test (extension 1 |
324 // regular extension, Extension 2 is UNPACKED so it counts as a DevMode | 381 // and 2). Extension 1 is a regular extension, Extension 2 is UNPACKED so it |
325 // extension. | 382 // counts as a DevMode extension. |
| 383 LoadExtensionWithAction("1", kId1, Manifest::COMMAND_LINE); |
| 384 LoadGenericExtension("2", kId2, Manifest::UNPACKED); |
| 385 LoadGenericExtension("3", kId3, Manifest::EXTERNAL_POLICY); |
| 386 |
326 scoped_ptr<TestDevModeBubbleController> controller( | 387 scoped_ptr<TestDevModeBubbleController> controller( |
327 new TestDevModeBubbleController(profile())); | 388 new TestDevModeBubbleController(profile())); |
328 | 389 |
329 // The list will contain one enabled unpacked extension. | 390 // The list will contain one enabled unpacked extension. |
330 EXPECT_TRUE(controller->ShouldShow()); | 391 EXPECT_TRUE(controller->ShouldShow()); |
331 std::vector<base::string16> dev_mode_extensions = | 392 std::vector<base::string16> dev_mode_extensions = |
332 controller->GetExtensionList(); | 393 controller->GetExtensionList(); |
333 ASSERT_EQ(2U, dev_mode_extensions.size()); | 394 ASSERT_EQ(2U, dev_mode_extensions.size()); |
334 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") == dev_mode_extensions[0]); | 395 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") == dev_mode_extensions[0]); |
335 EXPECT_TRUE(base::ASCIIToUTF16("Extension 1") == dev_mode_extensions[1]); | 396 EXPECT_TRUE(base::ASCIIToUTF16("Extension 1") == dev_mode_extensions[1]); |
336 EXPECT_EQ(0U, controller->link_click_count()); | 397 EXPECT_EQ(0U, controller->link_click_count()); |
337 EXPECT_EQ(0U, controller->dismiss_click_count()); | 398 EXPECT_EQ(0U, controller->dismiss_click_count()); |
338 EXPECT_EQ(0U, controller->action_click_count()); | 399 EXPECT_EQ(0U, controller->action_click_count()); |
339 | 400 |
340 // Simulate showing the bubble. | 401 // Simulate showing the bubble. |
341 FakeExtensionMessageBubble bubble; | 402 FakeExtensionMessageBubble bubble; |
342 bubble.set_action_on_show( | 403 bubble.set_action_on_show( |
343 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); | 404 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); |
344 controller->Show(&bubble); | 405 controller->Show(&bubble); |
345 EXPECT_EQ(0U, controller->link_click_count()); | 406 EXPECT_EQ(0U, controller->link_click_count()); |
346 EXPECT_EQ(0U, controller->action_click_count()); | 407 EXPECT_EQ(0U, controller->action_click_count()); |
347 EXPECT_EQ(1U, controller->dismiss_click_count()); | 408 EXPECT_EQ(1U, controller->dismiss_click_count()); |
348 EXPECT_TRUE(service_->GetExtensionById(extension_id1_, false) != NULL); | 409 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); |
349 EXPECT_TRUE(service_->GetExtensionById(extension_id2_, false) != NULL); | 410 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL); |
350 | 411 |
351 // Do it again, but now press different button (Disable). | 412 // Do it again, but now press different button (Disable). |
352 bubble.set_action_on_show( | 413 bubble.set_action_on_show( |
353 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); | 414 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); |
354 controller.reset(new TestDevModeBubbleController( | 415 controller.reset(new TestDevModeBubbleController( |
355 profile())); | 416 profile())); |
356 DevModeBubbleController::ClearProfileListForTesting(); | 417 DevModeBubbleController::ClearProfileListForTesting(); |
357 EXPECT_TRUE(controller->ShouldShow()); | 418 EXPECT_TRUE(controller->ShouldShow()); |
358 dev_mode_extensions = controller->GetExtensionList(); | 419 dev_mode_extensions = controller->GetExtensionList(); |
359 EXPECT_EQ(2U, dev_mode_extensions.size()); | 420 EXPECT_EQ(2U, dev_mode_extensions.size()); |
360 controller->Show(&bubble); // Simulate showing the bubble. | 421 controller->Show(&bubble); // Simulate showing the bubble. |
361 EXPECT_EQ(0U, controller->link_click_count()); | 422 EXPECT_EQ(0U, controller->link_click_count()); |
362 EXPECT_EQ(1U, controller->action_click_count()); | 423 EXPECT_EQ(1U, controller->action_click_count()); |
363 EXPECT_EQ(0U, controller->dismiss_click_count()); | 424 EXPECT_EQ(0U, controller->dismiss_click_count()); |
364 EXPECT_TRUE(service_->GetExtensionById(extension_id1_, false) == NULL); | 425 EXPECT_TRUE(service_->GetExtensionById(kId1, false) == NULL); |
365 EXPECT_TRUE(service_->GetExtensionById(extension_id2_, false) == NULL); | 426 EXPECT_TRUE(service_->GetExtensionById(kId2, false) == NULL); |
366 | 427 |
367 // Re-enable the extensions (disabled by the action button above). | 428 // Re-enable the extensions (disabled by the action button above). |
368 service_->EnableExtension(extension_id1_); | 429 service_->EnableExtension(kId1); |
369 service_->EnableExtension(extension_id2_); | 430 service_->EnableExtension(kId2); |
370 | 431 |
371 // Show the dialog a third time, but now press the learn more link. | 432 // Show the dialog a third time, but now press the learn more link. |
372 bubble.set_action_on_show( | 433 bubble.set_action_on_show( |
373 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); | 434 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); |
374 controller.reset(new TestDevModeBubbleController( | 435 controller.reset(new TestDevModeBubbleController( |
375 profile())); | 436 profile())); |
376 DevModeBubbleController::ClearProfileListForTesting(); | 437 DevModeBubbleController::ClearProfileListForTesting(); |
377 EXPECT_TRUE(controller->ShouldShow()); | 438 EXPECT_TRUE(controller->ShouldShow()); |
378 dev_mode_extensions = controller->GetExtensionList(); | 439 dev_mode_extensions = controller->GetExtensionList(); |
379 EXPECT_EQ(2U, dev_mode_extensions.size()); | 440 EXPECT_EQ(2U, dev_mode_extensions.size()); |
380 controller->Show(&bubble); // Simulate showing the bubble. | 441 controller->Show(&bubble); // Simulate showing the bubble. |
381 EXPECT_EQ(1U, controller->link_click_count()); | 442 EXPECT_EQ(1U, controller->link_click_count()); |
382 EXPECT_EQ(0U, controller->action_click_count()); | 443 EXPECT_EQ(0U, controller->action_click_count()); |
383 EXPECT_EQ(0U, controller->dismiss_click_count()); | 444 EXPECT_EQ(0U, controller->dismiss_click_count()); |
384 EXPECT_TRUE(service_->GetExtensionById(extension_id1_, false) != NULL); | 445 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); |
385 EXPECT_TRUE(service_->GetExtensionById(extension_id2_, false) != NULL); | 446 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL); |
386 | 447 |
387 // Now disable the unpacked extension. | 448 // Now disable the unpacked extension. |
388 service_->DisableExtension(extension_id1_, Extension::DISABLE_USER_ACTION); | 449 service_->DisableExtension(kId1, Extension::DISABLE_USER_ACTION); |
389 service_->DisableExtension(extension_id2_, Extension::DISABLE_USER_ACTION); | 450 service_->DisableExtension(kId2, Extension::DISABLE_USER_ACTION); |
390 | 451 |
391 controller.reset(new TestDevModeBubbleController( | 452 controller.reset(new TestDevModeBubbleController( |
392 profile())); | 453 profile())); |
393 DevModeBubbleController::ClearProfileListForTesting(); | 454 DevModeBubbleController::ClearProfileListForTesting(); |
394 EXPECT_FALSE(controller->ShouldShow()); | 455 EXPECT_FALSE(controller->ShouldShow()); |
395 dev_mode_extensions = controller->GetExtensionList(); | 456 dev_mode_extensions = controller->GetExtensionList(); |
396 EXPECT_EQ(0U, dev_mode_extensions.size()); | 457 EXPECT_EQ(0U, dev_mode_extensions.size()); |
397 } | 458 } |
398 | 459 |
| 460 // The feature this is meant to test is only implemented on Windows. |
| 461 #if defined(OS_WIN) |
| 462 #define MAYBE_SettingsApiControllerTest SettingsApiControllerTest |
| 463 #else |
| 464 #define MAYBE_SettingsApiControllerTest DISABLED_SettingsApiControllerTest |
| 465 #endif |
| 466 |
| 467 TEST_F(ExtensionMessageBubbleTest, MAYBE_SettingsApiControllerTest) { |
| 468 Init(); |
| 469 extensions::ExtensionPrefs* prefs = |
| 470 extensions::ExtensionPrefs::Get(profile()); |
| 471 |
| 472 for (int i = 0; i < 3; ++i) { |
| 473 switch (static_cast<SettingsApiOverrideType>(i)) { |
| 474 case BUBBLE_TYPE_HOME_PAGE: |
| 475 // Load two extensions overriding home page and one overriding something |
| 476 // unrelated (to check for interference). Extension 2 should still win |
| 477 // on the home page setting. |
| 478 LoadExtensionOverridingHome("1", kId1, Manifest::UNPACKED); |
| 479 LoadExtensionOverridingHome("2", kId2, Manifest::UNPACKED); |
| 480 LoadExtensionOverridingStart("3", kId3, Manifest::UNPACKED); |
| 481 break; |
| 482 case BUBBLE_TYPE_SEARCH_ENGINE: |
| 483 // We deliberately skip testing the search engine since it relies on |
| 484 // TemplateURLServiceFactory that isn't available while unit testing. |
| 485 // This test is only simulating the bubble interaction with the user and |
| 486 // that is more or less the same for the search engine as it is for the |
| 487 // others. |
| 488 continue; |
| 489 case BUBBLE_TYPE_STARTUP_PAGES: |
| 490 // Load two extensions overriding start page and one overriding |
| 491 // something unrelated (to check for interference). Extension 2 should |
| 492 // still win on the startup page setting. |
| 493 LoadExtensionOverridingStart("1", kId1, Manifest::UNPACKED); |
| 494 LoadExtensionOverridingStart("2", kId2, Manifest::UNPACKED); |
| 495 LoadExtensionOverridingHome("3", kId3, Manifest::UNPACKED); |
| 496 break; |
| 497 default: |
| 498 NOTREACHED(); |
| 499 break; |
| 500 } |
| 501 |
| 502 scoped_ptr<TestSettingsApiBubbleController> controller( |
| 503 new TestSettingsApiBubbleController( |
| 504 profile(), static_cast<SettingsApiOverrideType>(i))); |
| 505 |
| 506 // The list will contain one enabled unpacked extension (ext 2). |
| 507 EXPECT_TRUE(controller->ShouldShow(kId2)); |
| 508 std::vector<base::string16> override_extensions = |
| 509 controller->GetExtensionList(); |
| 510 ASSERT_EQ(1U, override_extensions.size()); |
| 511 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") == |
| 512 override_extensions[0].c_str()); |
| 513 EXPECT_EQ(0U, controller->link_click_count()); |
| 514 EXPECT_EQ(0U, controller->dismiss_click_count()); |
| 515 EXPECT_EQ(0U, controller->action_click_count()); |
| 516 |
| 517 // Simulate showing the bubble and dismissing it. |
| 518 FakeExtensionMessageBubble bubble; |
| 519 bubble.set_action_on_show( |
| 520 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); |
| 521 controller->Show(&bubble); |
| 522 EXPECT_EQ(0U, controller->link_click_count()); |
| 523 EXPECT_EQ(0U, controller->action_click_count()); |
| 524 EXPECT_EQ(1U, controller->dismiss_click_count()); |
| 525 // No extension should have become disabled. |
| 526 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); |
| 527 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL); |
| 528 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL); |
| 529 // Only extension 2 should have been acknowledged. |
| 530 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId1)); |
| 531 EXPECT_TRUE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2)); |
| 532 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3)); |
| 533 // Clean up after ourselves. |
| 534 prefs->SetSettingsApiBubbleBeenAcknowledged(kId2, false); |
| 535 |
| 536 // Simulate clicking the learn more link to dismiss it. |
| 537 bubble.set_action_on_show( |
| 538 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); |
| 539 controller.reset(new TestSettingsApiBubbleController( |
| 540 profile(), static_cast<SettingsApiOverrideType>(i))); |
| 541 controller->Show(&bubble); |
| 542 EXPECT_EQ(1U, controller->link_click_count()); |
| 543 EXPECT_EQ(0U, controller->action_click_count()); |
| 544 EXPECT_EQ(0U, controller->dismiss_click_count()); |
| 545 // No extension should have become disabled. |
| 546 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); |
| 547 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL); |
| 548 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL); |
| 549 // Only extension 2 should have been acknowledged. |
| 550 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId1)); |
| 551 EXPECT_TRUE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2)); |
| 552 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3)); |
| 553 // Clean up after ourselves. |
| 554 prefs->SetSettingsApiBubbleBeenAcknowledged(kId2, false); |
| 555 |
| 556 // Do it again, but now opt to disable the extension. |
| 557 bubble.set_action_on_show( |
| 558 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); |
| 559 controller.reset(new TestSettingsApiBubbleController( |
| 560 profile(), static_cast<SettingsApiOverrideType>(i))); |
| 561 EXPECT_TRUE(controller->ShouldShow(kId2)); |
| 562 override_extensions = controller->GetExtensionList(); |
| 563 EXPECT_EQ(1U, override_extensions.size()); |
| 564 controller->Show(&bubble); // Simulate showing the bubble. |
| 565 EXPECT_EQ(0U, controller->link_click_count()); |
| 566 EXPECT_EQ(1U, controller->action_click_count()); |
| 567 EXPECT_EQ(0U, controller->dismiss_click_count()); |
| 568 // Only extension 2 should have become disabled. |
| 569 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); |
| 570 EXPECT_TRUE(service_->GetExtensionById(kId2, false) == NULL); |
| 571 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL); |
| 572 // No extension should have been acknowledged (it got disabled). |
| 573 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId1)); |
| 574 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2)); |
| 575 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3)); |
| 576 |
| 577 // Clean up after ourselves. |
| 578 service_->UninstallExtension(kId1, false, NULL); |
| 579 service_->UninstallExtension(kId2, false, NULL); |
| 580 service_->UninstallExtension(kId3, false, NULL); |
| 581 } |
| 582 } |
| 583 |
399 } // namespace extensions | 584 } // namespace extensions |
OLD | NEW |