extension_unittest.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/extensions/extension.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/command_line.h" 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/file_util.h" 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h" 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/format_macros.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/json/json_file_value_serializer.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/path_service.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/stringprintf.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/strings/string_number_conversions.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/utf_string_conversions.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_paths.h" 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/chrome_switches.h" 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/extensions/api/commands/commands_handler.h" 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/extensions/api/plugins/plugins_handler.h" 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/extensions/background_info.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/extensions/command.h" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/extensions/extension_file_util.h" 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/extensions/extension_manifest_constants.h" 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/extensions/features/feature.h" 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/extensions/incognito_handler.h" 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/extensions/manifest.h" 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/extensions/manifest_handler.h" 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/extensions/permissions/api_permission.h" 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/extensions/permissions/permission_set.h" 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/extensions/permissions/socket_permission.h" 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/extensions/permissions/usb_device_permission.h" 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/url_constants.h" 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "extensions/common/error_utils.h" 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "extensions/common/extension_resource.h" 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "extensions/common/id_util.h" 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "googleurl/src/gurl.h" 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/mime_sniffer.h" 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/dns/mock_host_resolver.h" 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "skia/ext/image_operations.h" 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/skia/include/core/SkBitmap.h" 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/codec/png_codec.h" 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::SocketPermissionRequest; 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace keys = extension_manifest_keys; 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace values = extension_manifest_values; 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace errors = extension_manifest_errors; 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace extensions { 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)scoped_refptr<Extension> LoadManifestUnchecked( 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& dir, 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& test_file, 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::Location location, 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int extra_flags, 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string* error) { 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath path; 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PathService::Get(chrome::DIR_TEST_DATA, &path); 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) path = path.AppendASCII("extensions") 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) .AppendASCII(dir) 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) .AppendASCII(test_file); 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JSONFileValueSerializer serializer(path); 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<Value> result(serializer.Deserialize(NULL, error)); 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!result.get()) 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return NULL; 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension = Extension::Create( 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) path.DirName(), location, *static_cast<DictionaryValue*>(result.get()), 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extra_flags, error); 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return extension; 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static scoped_refptr<Extension> LoadManifest(const std::string& dir, 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& test_file, 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::Location location, 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int extra_flags) { 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string error; 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension = LoadManifestUnchecked(dir, test_file, 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location, extra_flags, &error); 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension) << test_file << ":" << error; 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return extension; 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static scoped_refptr<Extension> LoadManifest(const std::string& dir, 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& test_file, 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int extra_flags) { 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return LoadManifest(dir, test_file, Manifest::INVALID_LOCATION, extra_flags); 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static scoped_refptr<Extension> LoadManifest(const std::string& dir, 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& test_file) { 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return LoadManifest(dir, test_file, Extension::NO_FLAGS); 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static scoped_refptr<Extension> LoadManifestStrict( 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& dir, 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& test_file) { 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return LoadManifest(dir, test_file, Extension::NO_FLAGS); 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ExtensionTest : public testing::Test { 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void SetUp() OVERRIDE { 1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) testing::Test::SetUp(); 1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) (new BackgroundManifestHandler)->Register(); 1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) (new CommandsHandler)->Register(); 1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) (new ContentScriptsHandler)->Register(); 1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) (new PluginsHandler)->Register(); 1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) (new IncognitoHandler)->Register(); 1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void TearDown() OVERRIDE { 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ManifestHandler::ClearRegistryForTesting(); 1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// We persist location values in the preferences, so this is a sanity test that 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// someone doesn't accidentally change them. 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, LocationValuesTest) { 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(0, Manifest::INVALID_LOCATION); 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(1, Manifest::INTERNAL); 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(2, Manifest::EXTERNAL_PREF); 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(3, Manifest::EXTERNAL_REGISTRY); 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(4, Manifest::UNPACKED); 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(5, Manifest::COMPONENT); 1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(6, Manifest::EXTERNAL_PREF_DOWNLOAD); 1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(7, Manifest::EXTERNAL_POLICY_DOWNLOAD); 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(8, Manifest::COMMAND_LINE); 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, LocationPriorityTest) { 1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) for (int i = 0; i < Manifest::NUM_LOCATIONS; i++) { 1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::Location loc = static_cast<Manifest::Location>(i); 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // INVALID is not a valid location. 1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (loc == Manifest::INVALID_LOCATION) 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) continue; 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Comparing a location that has no rank will hit a CHECK. Do a 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // compare with every valid location, to be sure each one is covered. 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Check that no install source can override a componenet extension. 1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(Manifest::COMPONENT, 1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::GetHigherPriorityLocation(Manifest::COMPONENT, loc)); 1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(Manifest::COMPONENT, 1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::GetHigherPriorityLocation(loc, Manifest::COMPONENT)); 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Check that any source can override a user install. This might change 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // in the future, in which case this test should be updated. 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(loc, 1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::GetHigherPriorityLocation(Manifest::INTERNAL, loc)); 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(loc, 1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::GetHigherPriorityLocation(loc, Manifest::INTERNAL)); 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Check a few interesting cases that we know can happen: 1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, 1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::GetHigherPriorityLocation( 1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::EXTERNAL_POLICY_DOWNLOAD, 1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::EXTERNAL_PREF)); 1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(Manifest::EXTERNAL_PREF, 1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::GetHigherPriorityLocation( 1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::INTERNAL, 1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::EXTERNAL_PREF)); 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, GetResourceURLAndPath) { 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension = LoadManifestStrict("empty_manifest", 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "empty.json"); 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension.get()); 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(extension->url().spec() + "bar/baz.js", 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Extension::GetResourceURL(extension->url(), "bar/baz.js").spec()); 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(extension->url().spec() + "baz.js", 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Extension::GetResourceURL(extension->url(), 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "bar/../baz.js").spec()); 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(extension->url().spec() + "baz.js", 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Extension::GetResourceURL(extension->url(), "../baz.js").spec()); 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Test that absolute-looking paths ("/"-prefixed) are pasted correctly. 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(extension->url().spec() + "test.html", 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension->GetResourceURL("/test.html").spec()); 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, GetAbsolutePathNoError) { 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension = LoadManifestStrict("absolute_path", 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "absolute.json"); 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension.get()); 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string err; 1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::vector<InstallWarning> warnings; 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension_file_util::ValidateExtension(extension.get(), 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &err, &warnings)); 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0U, warnings.size()); 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(extension->path().AppendASCII("test.html").value(), 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension->GetResource("test.html").GetFilePath().value()); 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(extension->path().AppendASCII("test.js").value(), 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension->GetResource("test.js").GetFilePath().value()); 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, IdIsValid) { 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Extension::IdIsValid("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Extension::IdIsValid("pppppppppppppppppppppppppppppppp")); 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnop")); 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Extension::IdIsValid("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP")); 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmno")); 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnopa")); 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(Extension::IdIsValid("0123456789abcdef0123456789abcdef")); 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnoq")); 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmno0")); 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This test ensures that the mimetype sniffing code stays in sync with the 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// actual crx files that we test other parts of the system with. 2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, MimeTypeSniffing) { 2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath path; 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) path = path.AppendASCII("extensions").AppendASCII("good.crx"); 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string data; 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(file_util::ReadFileToString(path, &data)); 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string result; 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(net::SniffMimeType(data.c_str(), data.size(), 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL("http://www.example.com/foo.crx"), "", &result)); 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(std::string(Extension::kMimeType), result); 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) data.clear(); 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) result.clear(); 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) path = path.DirName().AppendASCII("bad_magic.crx"); 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(file_util::ReadFileToString(path, &data)); 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(net::SniffMimeType(data.c_str(), data.size(), 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL("http://www.example.com/foo.crx"), "", &result)); 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ("application/octet-stream", result); 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, EffectiveHostPermissions) { 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension; 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) URLPatternSet hosts; 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("effective_host_permissions", "empty.json"); 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0u, extension->GetEffectiveHostPermissions().patterns().size()); 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(hosts.MatchesURL(GURL("http://www.google.com"))); 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->HasEffectiveAccessToAllHosts()); 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("effective_host_permissions", "one_host.json"); 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) hosts = extension->GetEffectiveHostPermissions(); 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(hosts.MatchesURL(GURL("https://www.google.com"))); 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->HasEffectiveAccessToAllHosts()); 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("effective_host_permissions", 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "one_host_wildcard.json"); 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) hosts = extension->GetEffectiveHostPermissions(); 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(hosts.MatchesURL(GURL("http://google.com"))); 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(hosts.MatchesURL(GURL("http://foo.google.com"))); 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->HasEffectiveAccessToAllHosts()); 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("effective_host_permissions", "two_hosts.json"); 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) hosts = extension->GetEffectiveHostPermissions(); 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.reddit.com"))); 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->HasEffectiveAccessToAllHosts()); 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("effective_host_permissions", 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "https_not_considered.json"); 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) hosts = extension->GetEffectiveHostPermissions(); 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(hosts.MatchesURL(GURL("http://google.com"))); 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(hosts.MatchesURL(GURL("https://google.com"))); 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->HasEffectiveAccessToAllHosts()); 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("effective_host_permissions", 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "two_content_scripts.json"); 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) hosts = extension->GetEffectiveHostPermissions(); 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(hosts.MatchesURL(GURL("http://google.com"))); 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.reddit.com"))); 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension->GetActivePermissions()->HasEffectiveAccessToURL( 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL("http://www.reddit.com"))); 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(hosts.MatchesURL(GURL("http://news.ycombinator.com"))); 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension->GetActivePermissions()->HasEffectiveAccessToURL( 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL("http://news.ycombinator.com"))); 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->HasEffectiveAccessToAllHosts()); 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("effective_host_permissions", "all_hosts.json"); 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) hosts = extension->GetEffectiveHostPermissions(); 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(hosts.MatchesURL(GURL("http://test/"))); 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(hosts.MatchesURL(GURL("https://test/"))); 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension->HasEffectiveAccessToAllHosts()); 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("effective_host_permissions", "all_hosts2.json"); 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) hosts = extension->GetEffectiveHostPermissions(); 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(hosts.MatchesURL(GURL("http://test/"))); 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension->HasEffectiveAccessToAllHosts()); 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("effective_host_permissions", "all_hosts3.json"); 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) hosts = extension->GetEffectiveHostPermissions(); 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(hosts.MatchesURL(GURL("http://test/"))); 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(hosts.MatchesURL(GURL("https://test/"))); 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension->HasEffectiveAccessToAllHosts()); 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static bool CheckSocketPermission(scoped_refptr<Extension> extension, 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SocketPermissionRequest::OperationType type, 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* host, 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int port) { 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SocketPermission::CheckParam param(type, host, port); 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return extension->CheckAPIPermissionWithParam( 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) APIPermission::kSocket, ¶m); 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, SocketPermissions) { 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Set feature current channel to appropriate value. 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Feature::ScopedCurrentChannel scoped_channel( 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome::VersionInfo::CHANNEL_DEV); 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension; 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string error; 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("socket_permissions", "empty.json"); 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(CheckSocketPermission(extension, 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifestUnchecked("socket_permissions", 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "socket1.json", 3372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::INTERNAL, Extension::NO_FLAGS, 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &error); 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension == NULL); 3402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(ErrorUtils::FormatErrorMessage( 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) errors::kInvalidPermission, "socket"), error); 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("socket_permissions", "socket2.json"); 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(CheckSocketPermission(extension, 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(CheckSocketPermission( 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension, SocketPermissionRequest::UDP_BIND, "", 80)); 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(CheckSocketPermission( 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension, SocketPermissionRequest::UDP_BIND, "", 8888)); 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(CheckSocketPermission( 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension, SocketPermissionRequest::UDP_SEND_TO, "example.com", 1900)); 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(CheckSocketPermission( 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension, 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SocketPermissionRequest::UDP_SEND_TO, 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "239.255.255.250", 1900)); 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This tests the API permissions with an empty manifest (one that just 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// specifies a name and a version and nothing else). 3612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, ApiPermissions) { 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const struct { 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* permission_name; 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool expect_success; 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } kTests[] = { 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Negative test. 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "non_existing_permission", false }, 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Test default module/package permission. 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "browserAction", true }, 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "devtools", true }, 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "extension", true }, 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "i18n", true }, 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "pageAction", true }, 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "pageActions", true }, 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "test", true }, 3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Some negative tests. 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "bookmarks", false }, 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "cookies", false }, 3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "history", false }, 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Make sure we find the module name after stripping '.' and '/'. 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "browserAction/abcd/onClick", true }, 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "browserAction.abcd.onClick", true }, 3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Test Tabs functions. 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "tabs.create", true}, 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "tabs.duplicate", true}, 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "tabs.onRemoved", true}, 3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "tabs.remove", true}, 3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "tabs.update", true}, 3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "tabs.getSelected", true}, 3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "tabs.onUpdated", true }, 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Test getPermissionWarnings functions. Only one requires permissions. 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "management.getPermissionWarningsById", false }, 3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "management.getPermissionWarningsByManifest", true }, 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension; 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("empty_manifest", "empty.json"); 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(kTests[i].expect_success, 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension->HasAPIPermission(kTests[i].permission_name)) 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) << "Permission being tested: " << kTests[i].permission_name; 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, GetPermissionMessages_ManyApiPermissions) { 4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension; 4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("permissions", "many-apis.json"); 4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::vector<string16> warnings = extension->GetPermissionMessageStrings(); 4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(6u, warnings.size()); 4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ("Access your data on api.flickr.com", 4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UTF16ToUTF8(warnings[0])); 4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ("Read and modify your bookmarks", UTF16ToUTF8(warnings[1])); 4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ("Detect your physical location", UTF16ToUTF8(warnings[2])); 4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ("Read and modify your browsing history", UTF16ToUTF8(warnings[3])); 4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ("Access your tabs and browsing activity", UTF16ToUTF8(warnings[4])); 4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ("Manage your apps, extensions, and themes", 4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UTF16ToUTF8(warnings[5])); 4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, GetPermissionMessages_ManyHosts) { 4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension; 4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("permissions", "many-hosts.json"); 4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::vector<string16> warnings = extension->GetPermissionMessageStrings(); 4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(1u, warnings.size()); 4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ("Access your data on encrypted.google.com and www.google.com", 4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UTF16ToUTF8(warnings[0])); 4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, GetPermissionMessages_Plugins) { 4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension; 4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("permissions", "plugins.json"); 4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::vector<string16> warnings = extension->GetPermissionMessageStrings(); 4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We don't parse the plugins key on Chrome OS, so it should not ask for any 4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // permissions. 4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_CHROMEOS) 4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(0u, warnings.size()); 4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else 4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(1u, warnings.size()); 4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ("Access all data on your computer and the websites you visit", 4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UTF16ToUTF8(warnings[0])); 4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, WantsFileAccess) { 4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension; 4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL file_url("file:///etc/passwd"); 4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // <all_urls> permission 4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("permissions", "permissions_all_urls.json"); 4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension->wants_file_access()); 4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->CanExecuteScriptOnPage( 4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) file_url, file_url, -1, NULL, NULL)); 4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest( 4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "permissions", "permissions_all_urls.json", Extension::ALLOW_FILE_ACCESS); 4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension->wants_file_access()); 4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension->CanExecuteScriptOnPage( 4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) file_url, file_url, -1, NULL, NULL)); 4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // file:///* permission 4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("permissions", "permissions_file_scheme.json"); 4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension->wants_file_access()); 4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->CanExecuteScriptOnPage( 4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) file_url, file_url, -1, NULL, NULL)); 4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("permissions", "permissions_file_scheme.json", 4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Extension::ALLOW_FILE_ACCESS); 4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension->wants_file_access()); 4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension->CanExecuteScriptOnPage( 4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) file_url, file_url, -1, NULL, NULL)); 4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // http://* permission 4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("permissions", "permissions_http_scheme.json"); 4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->wants_file_access()); 4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->CanExecuteScriptOnPage( 4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) file_url, file_url, -1, NULL, NULL)); 4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("permissions", "permissions_http_scheme.json", 4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Extension::ALLOW_FILE_ACCESS); 4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->wants_file_access()); 4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->CanExecuteScriptOnPage( 4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) file_url, file_url, -1, NULL, NULL)); 4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // <all_urls> content script match 4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("permissions", "content_script_all_urls.json"); 4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension->wants_file_access()); 4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->CanExecuteScriptOnPage( 4862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) file_url, 4872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) file_url, 4882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) -1, 4892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &ContentScriptsInfo::GetContentScripts(extension)[0], 4902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NULL)); 4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("permissions", "content_script_all_urls.json", 4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Extension::ALLOW_FILE_ACCESS); 4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension->wants_file_access()); 4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension->CanExecuteScriptOnPage( 4952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) file_url, 4962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) file_url, 4972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) -1, 4982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &ContentScriptsInfo::GetContentScripts(extension)[0], 4992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NULL)); 5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // file:///* content script match 5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("permissions", "content_script_file_scheme.json"); 5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension->wants_file_access()); 5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->CanExecuteScriptOnPage( 5052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) file_url, 5062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) file_url, 5072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) -1, 5082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &ContentScriptsInfo::GetContentScripts(extension)[0], 5092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NULL)); 5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("permissions", "content_script_file_scheme.json", 5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Extension::ALLOW_FILE_ACCESS); 5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension->wants_file_access()); 5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension->CanExecuteScriptOnPage( 5142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) file_url, 5152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) file_url, 5162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) -1, 5172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &ContentScriptsInfo::GetContentScripts(extension)[0], 5182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NULL)); 5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // http://* content script match 5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("permissions", "content_script_http_scheme.json"); 5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->wants_file_access()); 5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->CanExecuteScriptOnPage( 5242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) file_url, 5252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) file_url, 5262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) -1, 5272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &ContentScriptsInfo::GetContentScripts(extension)[0], 5282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NULL)); 5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("permissions", "content_script_http_scheme.json", 5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Extension::ALLOW_FILE_ACCESS); 5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->wants_file_access()); 5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->CanExecuteScriptOnPage( 5332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) file_url, 5342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) file_url, 5352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) -1, 5362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &ContentScriptsInfo::GetContentScripts(extension)[0], 5372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NULL)); 5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, ExtraFlags) { 5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension; 5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("app", "manifest.json", Extension::FROM_WEBSTORE); 5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension->from_webstore()); 5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("app", "manifest.json", Extension::FROM_BOOKMARK); 5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension->from_bookmark()); 5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("app", "manifest.json", Extension::NO_FLAGS); 5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->from_bookmark()); 5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->from_webstore()); 5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, BrowserActionSynthesizesCommand) { 5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension; 5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("api_test/browser_action/synthesized", 5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "manifest.json"); 5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // An extension with a browser action but no extension command specified 5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // should get a command assigned to it. 5602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const extensions::Command* command = 5612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CommandsInfo::GetBrowserActionCommand(extension); 5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(command != NULL); 5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(ui::VKEY_UNKNOWN, command->accelerator().key_code()); 5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Base class for testing the CanExecuteScriptOnPage and CanCaptureVisiblePage 5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// methods of Extension for extensions with various permissions. 5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ExtensionScriptAndCaptureVisibleTest : public testing::Test { 5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ExtensionScriptAndCaptureVisibleTest() 5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : http_url("http://www.google.com"), 5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) http_url_with_path("http://www.google.com/index.html"), 5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) https_url("https://www.google.com"), 5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) file_url("file:///foo/bar"), 5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) favicon_url("chrome://favicon/http://www.google.com"), 5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension_url("chrome-extension://" + 5772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) id_util::GenerateIdForPath( 5782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath(FILE_PATH_LITERAL("foo")))), 5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) settings_url("chrome://settings"), 5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) about_url("about:flags") { 5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) urls_.insert(http_url); 5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) urls_.insert(http_url_with_path); 5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) urls_.insert(https_url); 5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) urls_.insert(file_url); 5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) urls_.insert(favicon_url); 5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) urls_.insert(extension_url); 5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) urls_.insert(settings_url); 5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) urls_.insert(about_url); 5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool AllowedScript(const Extension* extension, const GURL& url, 5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& top_url) { 5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return extension->CanExecuteScriptOnPage(url, top_url, -1, NULL, NULL); 5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool BlockedScript(const Extension* extension, const GURL& url, 5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& top_url) { 5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return !extension->CanExecuteScriptOnPage(url, top_url, -1, NULL, NULL); 5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool Allowed(const Extension* extension, const GURL& url) { 6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return Allowed(extension, url, -1); 6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool Allowed(const Extension* extension, const GURL& url, int tab_id) { 6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return (extension->CanExecuteScriptOnPage(url, url, tab_id, NULL, NULL) && 6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension->CanCaptureVisiblePage(url, tab_id, NULL)); 6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool CaptureOnly(const Extension* extension, const GURL& url) { 6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return CaptureOnly(extension, url, -1); 6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool CaptureOnly(const Extension* extension, const GURL& url, int tab_id) { 6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return !extension->CanExecuteScriptOnPage(url, url, tab_id, NULL, NULL) && 6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension->CanCaptureVisiblePage(url, tab_id, NULL); 6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool Blocked(const Extension* extension, const GURL& url) { 6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return Blocked(extension, url, -1); 6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool Blocked(const Extension* extension, const GURL& url, int tab_id) { 6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return !(extension->CanExecuteScriptOnPage(url, url, tab_id, NULL, NULL) || 6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension->CanCaptureVisiblePage(url, tab_id, NULL)); 6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool AllowedExclusivelyOnTab( 6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Extension* extension, 6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::set<GURL>& allowed_urls, 6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int tab_id) { 6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool result = true; 6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (std::set<GURL>::iterator it = urls_.begin(); it != urls_.end(); ++it) { 6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& url = *it; 6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (allowed_urls.count(url)) 6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) result &= Allowed(extension, url, tab_id); 6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) else 6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) result &= Blocked(extension, url, tab_id); 6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return result; 6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // URLs that are "safe" to provide scripting and capture visible tab access 6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to if the permissions allow it. 6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL http_url; 6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL http_url_with_path; 6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL https_url; 6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL file_url; 6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We should allow host permission but not scripting permission for favicon 6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // urls. 6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL favicon_url; 6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // URLs that regular extensions should never get access to. 6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL extension_url; 6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL settings_url; 6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL about_url; 6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The set of all URLs above. 6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::set<GURL> urls_; 6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ExtensionScriptAndCaptureVisibleTest, Permissions) { 6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Test <all_urls> for regular extensions. 6662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<Extension> extension = LoadManifestStrict("script_and_capture", 6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "extension_regular_all.json"); 6682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Allowed(extension, http_url)); 6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Allowed(extension, https_url)); 6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Blocked(extension, file_url)); 6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Blocked(extension, settings_url)); 6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(CaptureOnly(extension, favicon_url)); 6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Blocked(extension, about_url)); 6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Blocked(extension, extension_url)); 6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Test access to iframed content. 6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL within_extension_url = extension->GetResourceURL("page.html"); 6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AllowedScript(extension, http_url, http_url_with_path)); 6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AllowedScript(extension, https_url, http_url_with_path)); 6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AllowedScript(extension, http_url, within_extension_url)); 6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AllowedScript(extension, https_url, within_extension_url)); 6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(BlockedScript(extension, http_url, extension_url)); 6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(BlockedScript(extension, https_url, extension_url)); 6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->HasHostPermission(settings_url)); 6875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->HasHostPermission(about_url)); 6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension->HasHostPermission(favicon_url)); 6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Test * for scheme, which implies just the http/https schemes. 6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifestStrict("script_and_capture", 6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "extension_wildcard.json"); 6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Allowed(extension, http_url)); 6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Allowed(extension, https_url)); 6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Blocked(extension, settings_url)); 6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Blocked(extension, about_url)); 6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Blocked(extension, file_url)); 6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Blocked(extension, favicon_url)); 6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("script_and_capture", 7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "extension_wildcard_settings.json"); 7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Blocked(extension, settings_url)); 7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Having chrome://*/ should not work for regular extensions. Note that 7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // for favicon access, we require the explicit pattern chrome://favicon/*. 7055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string error; 7065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifestUnchecked("script_and_capture", 7075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "extension_wildcard_chrome.json", 7082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::INTERNAL, Extension::NO_FLAGS, 7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &error); 7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension == NULL); 7112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(ErrorUtils::FormatErrorMessage( 7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) errors::kInvalidPermissionScheme, "chrome://*/"), error); 7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Having chrome://favicon/* should not give you chrome://* 7155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifestStrict("script_and_capture", 7165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "extension_chrome_favicon_wildcard.json"); 7175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Blocked(extension, settings_url)); 7185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(CaptureOnly(extension, favicon_url)); 7195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Blocked(extension, about_url)); 7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension->HasHostPermission(favicon_url)); 7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Having http://favicon should not give you chrome://favicon 7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifestStrict("script_and_capture", 7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "extension_http_favicon.json"); 7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Blocked(extension, settings_url)); 7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Blocked(extension, favicon_url)); 7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Component extensions with <all_urls> should get everything. 7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("script_and_capture", "extension_component_all.json", 7302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::COMPONENT, Extension::NO_FLAGS); 7312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Allowed(extension, http_url)); 7322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Allowed(extension, https_url)); 7332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Allowed(extension, settings_url)); 7342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Allowed(extension, about_url)); 7352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Allowed(extension, favicon_url)); 7362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(extension->HasHostPermission(favicon_url)); 7372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Component extensions should only get access to what they ask for. 7392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension = LoadManifest("script_and_capture", 7402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "extension_component_google.json", Manifest::COMPONENT, 7412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Extension::NO_FLAGS); 7422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Allowed(extension, http_url)); 7432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, https_url)); 7442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, file_url)); 7452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, settings_url)); 7462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, favicon_url)); 7472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, about_url)); 7482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, extension_url)); 7492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(extension->HasHostPermission(settings_url)); 7502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionScriptAndCaptureVisibleTest, PermissionsWithChromeURLsEnabled) { 7542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CommandLine::ForCurrentProcess()->AppendSwitch( 7552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) switches::kExtensionsOnChromeURLs); 7562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<Extension> extension; 7582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Test <all_urls> for regular extensions. 7602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension = LoadManifestStrict("script_and_capture", 7612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "extension_regular_all.json"); 7622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Allowed(extension, http_url)); 7632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Allowed(extension, https_url)); 7642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, file_url)); 7652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, settings_url)); 7662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Allowed(extension, favicon_url)); // chrome:// requested 7672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, about_url)); 7682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, extension_url)); 7692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Test access to iframed content. 7712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GURL within_extension_url = extension->GetResourceURL("page.html"); 7722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(AllowedScript(extension, http_url, http_url_with_path)); 7732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(AllowedScript(extension, https_url, http_url_with_path)); 7742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(AllowedScript(extension, http_url, within_extension_url)); 7752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(AllowedScript(extension, https_url, within_extension_url)); 7762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(BlockedScript(extension, http_url, extension_url)); 7772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(BlockedScript(extension, https_url, extension_url)); 7782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(extension->HasHostPermission(settings_url)); 7802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(extension->HasHostPermission(about_url)); 7812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(extension->HasHostPermission(favicon_url)); 7822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Test * for scheme, which implies just the http/https schemes. 7842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension = LoadManifestStrict("script_and_capture", 7852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "extension_wildcard.json"); 7862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Allowed(extension, http_url)); 7872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Allowed(extension, https_url)); 7882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, settings_url)); 7892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, about_url)); 7902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, file_url)); 7912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, favicon_url)); 7922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension = LoadManifest("script_and_capture", 7932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "extension_wildcard_settings.json"); 7942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, settings_url)); 7952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Having chrome://*/ should work for regular extensions with the flag 7972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // enabled. 7982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string error; 7992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension = LoadManifestUnchecked("script_and_capture", 8002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "extension_wildcard_chrome.json", 8012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::INTERNAL, Extension::NO_FLAGS, 8022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &error); 8032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(extension == NULL); 8042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, http_url)); 8052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, https_url)); 8062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Allowed(extension, settings_url)); 8072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, about_url)); 8082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, file_url)); 8092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Allowed(extension, favicon_url)); // chrome:// requested 8102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Having chrome://favicon/* should not give you chrome://* 8122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension = LoadManifestStrict("script_and_capture", 8132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "extension_chrome_favicon_wildcard.json"); 8142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, settings_url)); 8152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Allowed(extension, favicon_url)); // chrome:// requested 8162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, about_url)); 8172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(extension->HasHostPermission(favicon_url)); 8182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Having http://favicon should not give you chrome://favicon 8202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension = LoadManifestStrict("script_and_capture", 8212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "extension_http_favicon.json"); 8222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, settings_url)); 8232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(Blocked(extension, favicon_url)); 8242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Component extensions with <all_urls> should get everything. 8262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension = LoadManifest("script_and_capture", "extension_component_all.json", 8272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::COMPONENT, Extension::NO_FLAGS); 8285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Allowed(extension, http_url)); 8295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Allowed(extension, https_url)); 8305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Allowed(extension, settings_url)); 8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Allowed(extension, about_url)); 8325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Allowed(extension, favicon_url)); 8335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension->HasHostPermission(favicon_url)); 8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Component extensions should only get access to what they ask for. 8365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension = LoadManifest("script_and_capture", 8372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "extension_component_google.json", Manifest::COMPONENT, 8385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Extension::NO_FLAGS); 8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Allowed(extension, http_url)); 8405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Blocked(extension, https_url)); 8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Blocked(extension, file_url)); 8425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Blocked(extension, settings_url)); 8435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Blocked(extension, favicon_url)); 8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Blocked(extension, about_url)); 8455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(Blocked(extension, extension_url)); 8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->HasHostPermission(settings_url)); 8475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(ExtensionScriptAndCaptureVisibleTest, TabSpecific) { 8505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension = 8515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoadManifestStrict("script_and_capture", "tab_specific.json"); 8525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->GetTabSpecificPermissions(0).get()); 8545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->GetTabSpecificPermissions(1).get()); 8555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->GetTabSpecificPermissions(2).get()); 8565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::set<GURL> no_urls; 8585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 0)); 8605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 1)); 8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 2)); 8625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) URLPatternSet allowed_hosts; 8645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) allowed_hosts.AddPattern(URLPattern(URLPattern::SCHEME_ALL, 8655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) http_url.spec())); 8665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::set<GURL> allowed_urls; 8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) allowed_urls.insert(http_url); 8685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // http_url_with_path() will also be allowed, because Extension should be 8695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // considering the security origin of the URL not the URL itself, and 8705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // http_url is in allowed_hosts. 8715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) allowed_urls.insert(http_url_with_path); 8725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 8745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<PermissionSet> permissions( 8755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new PermissionSet(APIPermissionSet(), allowed_hosts, URLPatternSet())); 8765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension->UpdateTabSpecificPermissions(0, permissions); 8775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(permissions->explicit_hosts(), 8785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension->GetTabSpecificPermissions(0)->explicit_hosts()); 8795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AllowedExclusivelyOnTab(extension, allowed_urls, 0)); 8825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 1)); 8835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 2)); 8845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension->ClearTabSpecificPermissions(0); 8865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->GetTabSpecificPermissions(0).get()); 8875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 0)); 8895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 1)); 8905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 2)); 8915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::set<GURL> more_allowed_urls = allowed_urls; 8935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) more_allowed_urls.insert(https_url); 8945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) URLPatternSet more_allowed_hosts = allowed_hosts; 8955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) more_allowed_hosts.AddPattern(URLPattern(URLPattern::SCHEME_ALL, 8965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) https_url.spec())); 8975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 8995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<PermissionSet> permissions( 9005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new PermissionSet(APIPermissionSet(), allowed_hosts, URLPatternSet())); 9015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension->UpdateTabSpecificPermissions(0, permissions); 9025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(permissions->explicit_hosts(), 9035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension->GetTabSpecificPermissions(0)->explicit_hosts()); 9045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) permissions = new PermissionSet(APIPermissionSet(), 9065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) more_allowed_hosts, 9075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) URLPatternSet()); 9085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension->UpdateTabSpecificPermissions(1, permissions); 9095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(permissions->explicit_hosts(), 9105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension->GetTabSpecificPermissions(1)->explicit_hosts()); 9115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 9125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AllowedExclusivelyOnTab(extension, allowed_urls, 0)); 9145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AllowedExclusivelyOnTab(extension, more_allowed_urls, 1)); 9155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 2)); 9165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension->ClearTabSpecificPermissions(0); 9185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->GetTabSpecificPermissions(0).get()); 9195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 0)); 9215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AllowedExclusivelyOnTab(extension, more_allowed_urls, 1)); 9225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 2)); 9235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension->ClearTabSpecificPermissions(1); 9255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->GetTabSpecificPermissions(1).get()); 9265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 0)); 9285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 1)); 9295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 2)); 9305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 9335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)enum SyncTestExtensionType { 9345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXTENSION, 9355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) APP, 9365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) USER_SCRIPT, 9375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) THEME 9385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 9395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static scoped_refptr<Extension> MakeSyncTestExtension( 9415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SyncTestExtensionType type, 9425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& update_url, 9435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& launch_url, 9442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::Location location, 9455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int num_plugins, 9462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& extension_path, 9475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int creation_flags) { 9485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DictionaryValue source; 9495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) source.SetString(extension_manifest_keys::kName, 9505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "PossiblySyncableExtension"); 9515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) source.SetString(extension_manifest_keys::kVersion, "0.0.0.0"); 9525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (type == APP) 9535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) source.SetString(extension_manifest_keys::kApp, "true"); 9545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (type == THEME) 9555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) source.Set(extension_manifest_keys::kTheme, new DictionaryValue()); 9565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!update_url.is_empty()) { 9575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) source.SetString(extension_manifest_keys::kUpdateURL, 9585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) update_url.spec()); 9595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 9605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!launch_url.is_empty()) { 9615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) source.SetString(extension_manifest_keys::kLaunchWebURL, 9625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) launch_url.spec()); 9635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 9645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (type != THEME) { 9655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) source.SetBoolean(extension_manifest_keys::kConvertedFromUserScript, 9665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) type == USER_SCRIPT); 9675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ListValue* plugins = new ListValue(); 9685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (int i = 0; i < num_plugins; ++i) { 9695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DictionaryValue* plugin = new DictionaryValue(); 9705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) plugin->SetString(extension_manifest_keys::kPluginsPath, ""); 9715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) plugins->Set(i, plugin); 9725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 9735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) source.Set(extension_manifest_keys::kPlugins, plugins); 9745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 9755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string error; 9775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension = Extension::Create( 9785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extension_path, location, source, creation_flags, &error); 9795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension); 9805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ("", error); 9815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return extension; 9825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static const char kValidUpdateUrl1[] = 9855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "http://clients2.google.com/service/update2/crx"; 9865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static const char kValidUpdateUrl2[] = 9875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "https://clients2.google.com/service/update2/crx"; 9885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, GetSyncTypeNormalExtensionNoUpdateUrl) { 9915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension( 9925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 9932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::INTERNAL, 0, base::FilePath(), 9945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Extension::NO_FLAGS)); 9955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 9965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// http://crbug.com/172712 9992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, DISABLED_GetSyncTypeUserScriptValidUpdateUrl) { 10005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension( 10015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MakeSyncTestExtension(USER_SCRIPT, GURL(kValidUpdateUrl1), GURL(), 10022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::INTERNAL, 0, base::FilePath(), 10035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Extension::NO_FLAGS)); 10045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 10055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, GetSyncTypeUserScriptNoUpdateUrl) { 10085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension( 10095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MakeSyncTestExtension(USER_SCRIPT, GURL(), GURL(), 10102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::INTERNAL, 0, base::FilePath(), 10115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Extension::NO_FLAGS)); 10125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 10135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, GetSyncTypeThemeNoUpdateUrl) { 10165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension( 10175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MakeSyncTestExtension(THEME, GURL(), GURL(), 10182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::INTERNAL, 0, base::FilePath(), 10195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Extension::NO_FLAGS)); 10205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 10215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, GetSyncTypeExtensionWithLaunchUrl) { 10245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension( 10255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MakeSyncTestExtension(EXTENSION, GURL(), GURL("http://www.google.com"), 10262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::INTERNAL, 0, base::FilePath(), 10275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Extension::NO_FLAGS)); 10285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 10295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, GetSyncTypeExtensionExternal) { 10325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension( 10335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 10342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::EXTERNAL_PREF, 0, base::FilePath(), 10355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Extension::NO_FLAGS)); 10365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 10385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, GetSyncTypeUserScriptThirdPartyUpdateUrl) { 10415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension( 10425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MakeSyncTestExtension( 10435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) USER_SCRIPT, GURL("http://third-party.update_url.com"), GURL(), 10442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::INTERNAL, 0, base::FilePath(), Extension::NO_FLAGS)); 10455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 10465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, OnlyDisplayAppsInLauncher) { 10495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension( 10505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 10512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::INTERNAL, 0, base::FilePath(), 10525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Extension::NO_FLAGS)); 10535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->ShouldDisplayInAppLauncher()); 10555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension->ShouldDisplayInNewTabPage()); 10565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> app( 10585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MakeSyncTestExtension(APP, GURL(), GURL("http://www.google.com"), 10592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::INTERNAL, 0, base::FilePath(), 10605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Extension::NO_FLAGS)); 10615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(app->ShouldDisplayInAppLauncher()); 10625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(app->ShouldDisplayInNewTabPage()); 10635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, DisplayInXManifestProperties) { 10665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DictionaryValue manifest; 10675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) manifest.SetString(keys::kName, "TestComponentApp"); 10685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) manifest.SetString(keys::kVersion, "0.0.0.0"); 10695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) manifest.SetString(keys::kApp, "true"); 10705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) manifest.SetString(keys::kPlatformAppBackgroundPage, ""); 10715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string error; 10735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> app; 10745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Default to true. 10765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) app = Extension::Create( 10772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath(), Manifest::COMPONENT, manifest, 0, &error); 10785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(error, std::string()); 10795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(app->ShouldDisplayInAppLauncher()); 10805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(app->ShouldDisplayInNewTabPage()); 10815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Value display_in_NTP defaults to display_in_launcher. 10835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) manifest.SetBoolean(keys::kDisplayInLauncher, false); 10845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) app = Extension::Create( 10852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath(), Manifest::COMPONENT, manifest, 0, &error); 10865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(error, std::string()); 10875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(app->ShouldDisplayInAppLauncher()); 10885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(app->ShouldDisplayInNewTabPage()); 10895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Value display_in_NTP = true overriding display_in_launcher = false. 10915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) manifest.SetBoolean(keys::kDisplayInNewTabPage, true); 10925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) app = Extension::Create( 10932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath(), Manifest::COMPONENT, manifest, 0, &error); 10945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(error, std::string()); 10955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(app->ShouldDisplayInAppLauncher()); 10965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(app->ShouldDisplayInNewTabPage()); 10975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Value display_in_NTP = false only, overrides default = true. 10995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) manifest.Remove(keys::kDisplayInLauncher, NULL); 11005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) manifest.SetBoolean(keys::kDisplayInNewTabPage, false); 11015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) app = Extension::Create( 11022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath(), Manifest::COMPONENT, manifest, 0, &error); 11035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(error, std::string()); 11045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(app->ShouldDisplayInAppLauncher()); 11055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(app->ShouldDisplayInNewTabPage()); 11065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Error checking. 11085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) manifest.SetString(keys::kDisplayInNewTabPage, "invalid"); 11095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) app = Extension::Create( 11102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath(), Manifest::COMPONENT, manifest, 0, &error); 11115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(error, std::string(errors::kInvalidDisplayInNewTabPage)); 11125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, OnlySyncInternal) { 11155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension_internal( 11165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 11172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::INTERNAL, 0, base::FilePath(), 11185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Extension::NO_FLAGS)); 11195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(extension_internal->IsSyncable()); 11205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension_noninternal( 11225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 11232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::COMPONENT, 0, base::FilePath(), 11245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Extension::NO_FLAGS)); 11255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension_noninternal->IsSyncable()); 11265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, DontSyncDefault) { 11295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension_default( 11305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 11312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::INTERNAL, 0, base::FilePath(), 11325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Extension::WAS_INSTALLED_BY_DEFAULT)); 11335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(extension_default->IsSyncable()); 11345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, OptionalOnlyPermission) { 11372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Set feature current channel to dev because the only permission that must 11382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // be optional (usbDevices) is only available on dev channel. 11392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Feature::ScopedCurrentChannel scoped_channel( 11402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chrome::VersionInfo::CHANNEL_DEV); 11412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<Extension> extension; 11432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string error; 11442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension = LoadManifestUnchecked("optional_only_permission", 11452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "manifest1.json", 11462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::INTERNAL, Extension::NO_FLAGS, 11472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &error); 11482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(extension == NULL); 11492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(ErrorUtils::FormatErrorMessage( 11502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) errors::kPermissionMustBeOptional, "usbDevices"), error); 11512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) error.clear(); 11532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension = LoadManifestUnchecked("optional_only_permission", 11542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "manifest2.json", 11552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::INTERNAL, Extension::NO_FLAGS, 11562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &error); 11572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(extension != NULL); 11582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(error.empty()); 11592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 11602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// These last 2 tests don't make sense on Chrome OS, where extension plugins 11625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// are not allowed. 11635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(OS_CHROMEOS) 11642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, GetSyncTypeExtensionWithPlugin) { 11655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension( 11665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 11672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::INTERNAL, 1, base::FilePath(), 11685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Extension::NO_FLAGS)); 11695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (extension) 11705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 11715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) { 11745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<Extension> extension( 11755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 11762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Manifest::INTERNAL, 2, base::FilePath(), 11775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Extension::NO_FLAGS)); 11785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (extension) 11795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 11805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // !defined(OS_CHROMEOS) 11822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace extensions 1184