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

Side by Side Diff: chrome/common/extensions/manifest_tests/extension_manifests_platformapp_unittest.cc

Issue 1047943002: Cache --whitelisted-extension-id in SimpleFeature. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | extensions/common/features/simple_feature.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/json/json_file_value_serializer.h" 6 #include "base/json/json_file_value_serializer.h"
7 #include "base/memory/linked_ptr.h" 7 #include "base/memory/linked_ptr.h"
8 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" 8 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
9 #include "chrome/common/extensions/manifest_tests/chrome_manifest_test.h" 9 #include "chrome/common/extensions/manifest_tests/chrome_manifest_test.h"
10 #include "extensions/common/error_utils.h" 10 #include "extensions/common/error_utils.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 "'background' is only allowed for extensions, hosted apps, and legacy " 57 "'background' is only allowed for extensions, hosted apps, and legacy "
58 "packaged apps, but this is a packaged app."), 58 "packaged apps, but this is a packaged app."),
59 Testcase("incognito_invalid_platform_app.json", 59 Testcase("incognito_invalid_platform_app.json",
60 "'incognito' is only allowed for extensions and legacy packaged apps, " 60 "'incognito' is only allowed for extensions and legacy packaged apps, "
61 "but this is a packaged app."), 61 "but this is a packaged app."),
62 }; 62 };
63 RunTestcases( 63 RunTestcases(
64 warning_testcases, arraysize(warning_testcases), EXPECT_TYPE_WARNING); 64 warning_testcases, arraysize(warning_testcases), EXPECT_TYPE_WARNING);
65 } 65 }
66 66
67 TEST_F(PlatformAppsManifestTest, PlatformAppContentSecurityPolicy) { 67 namespace {
68
69 class WhitelistedPlatformAppsManifestTest : public PlatformAppsManifestTest {
70 public:
71 static void SetUpTestCase() {
72 // The whitelisted extension ID is cached, so set it here during test setup.
73 // This is the ID corresponding to the base 64 encoded key in the
74 // init_platform_app_csp.json manifest.
75 std::string test_id = "ahplfneplbnjcflhdgkkjeiglkkfeelb";
76 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
77 switches::kWhitelistedExtensionID, test_id);
not at google - send to devlin 2015/03/31 22:21:51 This is why I wrote ScopedCommandLineSwitch: http
jackhou1 2015/03/31 22:55:38 Unfortunately ScopedCommandLineSwitch doesn't real
not at google - send to devlin 2015/04/01 17:08:21 It's not so much the cache that I want to reset, r
jackhou1 2015/04/02 01:28:57 Looks like this requires a bit of a refactor, mayb
78 }
79 };
80
81 } // namespace
82
83 TEST_F(WhitelistedPlatformAppsManifestTest, PlatformAppContentSecurityPolicy) {
68 // Normal platform apps can't specify a CSP value. 84 // Normal platform apps can't specify a CSP value.
69 Testcase warning_testcases[] = { 85 Testcase warning_testcases[] = {
70 Testcase( 86 Testcase(
71 "init_platform_app_csp_warning_1.json", 87 "init_platform_app_csp_warning_1.json",
72 "'content_security_policy' is only allowed for extensions and legacy " 88 "'content_security_policy' is only allowed for extensions and legacy "
73 "packaged apps, but this is a packaged app."), 89 "packaged apps, but this is a packaged app."),
74 Testcase( 90 Testcase(
75 "init_platform_app_csp_warning_2.json", 91 "init_platform_app_csp_warning_2.json",
76 "'app.content_security_policy' is not allowed for specified extension " 92 "'app.content_security_policy' is not allowed for specified extension "
77 "ID.") 93 "ID.")
78 }; 94 };
79 RunTestcases( 95 RunTestcases(
80 warning_testcases, arraysize(warning_testcases), EXPECT_TYPE_WARNING); 96 warning_testcases, arraysize(warning_testcases), EXPECT_TYPE_WARNING);
81 97
82 // Whitelisted ones can (this is the ID corresponding to the base 64 encoded 98 // Whitelisted ones can.
83 // key in the init_platform_app_csp.json manifest.)
84 std::string test_id = "ahplfneplbnjcflhdgkkjeiglkkfeelb";
85 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
86 switches::kWhitelistedExtensionID, test_id);
87 scoped_refptr<Extension> extension = 99 scoped_refptr<Extension> extension =
88 LoadAndExpectSuccess("init_platform_app_csp.json"); 100 LoadAndExpectSuccess("init_platform_app_csp.json");
89 EXPECT_EQ(0U, extension->install_warnings().size()) 101 EXPECT_EQ(0U, extension->install_warnings().size())
90 << "Unexpected warning " << extension->install_warnings()[0].message; 102 << "Unexpected warning " << extension->install_warnings()[0].message;
91 EXPECT_TRUE(extension->is_platform_app()); 103 EXPECT_TRUE(extension->is_platform_app());
92 EXPECT_EQ("default-src 'self' https://www.google.com;", 104 EXPECT_EQ("default-src 'self' https://www.google.com;",
93 CSPInfo::GetResourceContentSecurityPolicy(extension.get(), 105 CSPInfo::GetResourceContentSecurityPolicy(extension.get(),
94 std::string())); 106 std::string()));
95 107
96 // But even whitelisted ones must specify a secure policy. 108 // But even whitelisted ones must specify a secure policy.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 152
141 // Now try again with the experimental flag set. 153 // Now try again with the experimental flag set.
142 base::CommandLine::ForCurrentProcess()->AppendSwitch( 154 base::CommandLine::ForCurrentProcess()->AppendSwitch(
143 switches::kEnableExperimentalExtensionApis); 155 switches::kEnableExperimentalExtensionApis);
144 for (size_t i = 0; i < arraysize(kPlatformAppExperimentalApis); ++i) { 156 for (size_t i = 0; i < arraysize(kPlatformAppExperimentalApis); ++i) {
145 LoadAndExpectSuccess(ManifestData(manifests[i].get(), "")); 157 LoadAndExpectSuccess(ManifestData(manifests[i].get(), ""));
146 } 158 }
147 } 159 }
148 160
149 } // namespace extensions 161 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/common/features/simple_feature.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698