Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: chrome/browser/extensions/extension_ui_unittest.cc

Issue 874683005: [Extensions] Enable the scripts-require-action feature based on all-urls pref (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated metrics Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/json/json_file_value_serializer.h" 6 #include "base/json/json_file_value_serializer.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 FeatureSwitch::scripts_require_action(), true)); 322 FeatureSwitch::scripts_require_action(), true));
323 // Two extensions - one with all urls, one without. 323 // Two extensions - one with all urls, one without.
324 scoped_refptr<const Extension> all_urls_extension = CreateExtension( 324 scoped_refptr<const Extension> all_urls_extension = CreateExtension(
325 "all_urls", ListBuilder().Append(kAllHostsPermission).Pass()); 325 "all_urls", ListBuilder().Append(kAllHostsPermission).Pass());
326 scoped_refptr<const Extension> no_urls_extension = 326 scoped_refptr<const Extension> no_urls_extension =
327 CreateExtension("no urls", ListBuilder().Pass()); 327 CreateExtension("no urls", ListBuilder().Pass());
328 328
329 scoped_ptr<base::DictionaryValue> value(handler()->CreateExtensionDetailValue( 329 scoped_ptr<base::DictionaryValue> value(handler()->CreateExtensionDetailValue(
330 all_urls_extension.get(), std::vector<ExtensionPage>(), NULL)); 330 all_urls_extension.get(), std::vector<ExtensionPage>(), NULL));
331 bool result = false; 331 bool result = false;
332 const std::string kWantsAllUrls = "wantsAllUrls"; 332 const std::string kShowAllUrls = "showAllUrls";
333 const std::string kAllowAllUrls = "allowAllUrls"; 333 const std::string kAllowAllUrls = "allowAllUrls";
334 334
335 // The extension should want all urls, but not currently have it. 335 // The extension should want all urls, but not currently have it.
336 EXPECT_TRUE(value->GetBoolean(kWantsAllUrls, &result)); 336 EXPECT_TRUE(value->GetBoolean(kShowAllUrls, &result));
337 EXPECT_TRUE(result); 337 EXPECT_TRUE(result);
338 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); 338 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result));
339 EXPECT_FALSE(result); 339 EXPECT_FALSE(result);
340 340
341 // Give the extension all urls. 341 // Give the extension all urls.
342 util::SetAllowedScriptingOnAllUrls( 342 util::SetAllowedScriptingOnAllUrls(all_urls_extension->id(), profile(), true);
343 all_urls_extension->id(), profile(), true);
344 343
345 // Now the extension should both want and have all urls. 344 // Now the extension should both want and have all urls.
346 value.reset(handler()->CreateExtensionDetailValue( 345 value.reset(handler()->CreateExtensionDetailValue(
347 all_urls_extension.get(), std::vector<ExtensionPage>(), NULL)); 346 all_urls_extension.get(), std::vector<ExtensionPage>(), NULL));
348 EXPECT_TRUE(value->GetBoolean(kWantsAllUrls, &result)); 347 EXPECT_TRUE(value->GetBoolean(kShowAllUrls, &result));
349 EXPECT_TRUE(result); 348 EXPECT_TRUE(result);
350 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); 349 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result));
351 EXPECT_TRUE(result); 350 EXPECT_TRUE(result);
352 351
353 // The other extension should neither want nor have all urls. 352 // The other extension should neither want nor have all urls.
354 value.reset(handler()->CreateExtensionDetailValue( 353 value.reset(handler()->CreateExtensionDetailValue(
355 no_urls_extension.get(), std::vector<ExtensionPage>(), NULL)); 354 no_urls_extension.get(), std::vector<ExtensionPage>(), NULL));
356 EXPECT_TRUE(value->GetBoolean(kWantsAllUrls, &result)); 355 EXPECT_TRUE(value->GetBoolean(kShowAllUrls, &result));
357 EXPECT_FALSE(result); 356 EXPECT_FALSE(result);
358 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); 357 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result));
359 EXPECT_FALSE(result); 358 EXPECT_FALSE(result);
360 359
360 // Revoke the first extension's permissions.
361 util::SetAllowedScriptingOnAllUrls(
362 all_urls_extension->id(), profile(), false);
363
361 // Turn off the switch and load another extension (so permissions are 364 // Turn off the switch and load another extension (so permissions are
362 // re-initialized). 365 // re-initialized).
363 enable_scripts_switch.reset(); 366 enable_scripts_switch.reset();
364 367
365 // Even though the extension has the all urls preference, the checkbox 368 // Since the extension doesn't have access to all urls (but normally would),
366 // shouldn't show up with the switch off. 369 // the extension should have the "want" flag even with the switch off.
367 value.reset(handler()->CreateExtensionDetailValue( 370 value.reset(handler()->CreateExtensionDetailValue(
368 all_urls_extension.get(), std::vector<ExtensionPage>(), NULL)); 371 all_urls_extension.get(), std::vector<ExtensionPage>(), NULL));
369 EXPECT_TRUE(value->GetBoolean(kWantsAllUrls, &result)); 372 EXPECT_TRUE(value->GetBoolean(kShowAllUrls, &result));
373 EXPECT_TRUE(result);
374 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result));
375 EXPECT_FALSE(result);
376
377 // If we grant the extension all urls, then it should no longer "want" it,
378 // since it is back in its normal state (with the switch off).
379 util::SetAllowedScriptingOnAllUrls(all_urls_extension->id(), profile(), true);
380 value.reset(handler()->CreateExtensionDetailValue(
381 all_urls_extension.get(), std::vector<ExtensionPage>(), NULL));
382 EXPECT_TRUE(value->GetBoolean(kShowAllUrls, &result));
370 EXPECT_FALSE(result); 383 EXPECT_FALSE(result);
371 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); 384 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result));
372 EXPECT_TRUE(result); 385 EXPECT_TRUE(result);
373 386
374 // Load another extension with all urls (so permissions get re-init'd). 387 // Load another extension with all urls (so permissions get re-init'd).
375 all_urls_extension = CreateExtension( 388 all_urls_extension = CreateExtension(
376 "all_urls_II", ListBuilder().Append(kAllHostsPermission).Pass()); 389 "all_urls_II", ListBuilder().Append(kAllHostsPermission).Pass());
377 390
378 // Even though the extension has all_urls permission, the checkbox shouldn't 391 // Even though the extension has all_urls permission, the checkbox shouldn't
379 // show up without the switch. 392 // show up without the switch.
380 value.reset(handler()->CreateExtensionDetailValue( 393 value.reset(handler()->CreateExtensionDetailValue(
381 all_urls_extension.get(), std::vector<ExtensionPage>(), NULL)); 394 all_urls_extension.get(), std::vector<ExtensionPage>(), NULL));
382 EXPECT_TRUE(value->GetBoolean(kWantsAllUrls, &result)); 395 EXPECT_TRUE(value->GetBoolean(kShowAllUrls, &result));
383 EXPECT_FALSE(result); 396 EXPECT_FALSE(result);
384 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); 397 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result));
385 EXPECT_FALSE(result); 398 EXPECT_TRUE(result);
386 } 399 }
387 400
388 } // namespace extensions 401 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/crx_installer_browsertest.cc ('k') | chrome/browser/extensions/extension_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698