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

Side by Side Diff: chrome/renderer/extensions/renderer_permissions_policy_delegate_unittest.cc

Issue 1739183003: Make extensions::DictionaryBuilder and extensions::ListValue unmovable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <utility> 5 #include <utility>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/common/extensions/extension_constants.h" 8 #include "chrome/common/extensions/extension_constants.h"
9 #include "chrome/renderer/extensions/chrome_extensions_dispatcher_delegate.h" 9 #include "chrome/renderer/extensions/chrome_extensions_dispatcher_delegate.h"
10 #include "chrome/renderer/extensions/renderer_permissions_policy_delegate.h" 10 #include "chrome/renderer/extensions/renderer_permissions_policy_delegate.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 scoped_ptr<content::MockRenderThread> render_thread_; 44 scoped_ptr<content::MockRenderThread> render_thread_;
45 scoped_ptr<ExtensionsRendererClient> renderer_client_; 45 scoped_ptr<ExtensionsRendererClient> renderer_client_;
46 scoped_ptr<DispatcherDelegate> extension_dispatcher_delegate_; 46 scoped_ptr<DispatcherDelegate> extension_dispatcher_delegate_;
47 scoped_ptr<Dispatcher> extension_dispatcher_; 47 scoped_ptr<Dispatcher> extension_dispatcher_;
48 scoped_ptr<RendererPermissionsPolicyDelegate> policy_delegate_; 48 scoped_ptr<RendererPermissionsPolicyDelegate> policy_delegate_;
49 }; 49 };
50 50
51 scoped_refptr<const Extension> CreateTestExtension(const std::string& id) { 51 scoped_refptr<const Extension> CreateTestExtension(const std::string& id) {
52 return ExtensionBuilder() 52 return ExtensionBuilder()
53 .SetManifest( 53 .SetManifest(
54 std::move(DictionaryBuilder() 54 DictionaryBuilder()
55 .Set("name", "Extension with ID " + id) 55 .Set("name", "Extension with ID " + id)
56 .Set("version", "1.0") 56 .Set("version", "1.0")
57 .Set("manifest_version", 2) 57 .Set("manifest_version", 2)
58 .Set("permissions", 58 .Set("permissions", ListBuilder().Append("<all_urls>").Build())
59 std::move(ListBuilder().Append("<all_urls>"))))) 59 .Build())
60 .SetID(id) 60 .SetID(id)
61 .Build(); 61 .Build();
62 } 62 }
63 63
64 } // namespace 64 } // namespace
65 65
66 // Tests that CanAccessPage returns false for the any process 66 // Tests that CanAccessPage returns false for the any process
67 // which hosts the webstore. 67 // which hosts the webstore.
68 TEST_F(RendererPermissionsPolicyDelegateTest, CannotScriptWebstore) { 68 TEST_F(RendererPermissionsPolicyDelegateTest, CannotScriptWebstore) {
69 GURL kAnyUrl("http://example.com/"); 69 GURL kAnyUrl("http://example.com/");
70 scoped_refptr<const Extension> extension(CreateTestExtension("a")); 70 scoped_refptr<const Extension> extension(CreateTestExtension("a"));
71 std::string error; 71 std::string error;
72 72
73 EXPECT_TRUE(extension->permissions_data()->CanAccessPage(extension.get(), 73 EXPECT_TRUE(extension->permissions_data()->CanAccessPage(extension.get(),
74 kAnyUrl, -1, &error)) 74 kAnyUrl, -1, &error))
75 << error; 75 << error;
76 76
77 // Pretend we are in the webstore process. We should not be able to execute 77 // Pretend we are in the webstore process. We should not be able to execute
78 // script. 78 // script.
79 scoped_refptr<const Extension> webstore_extension( 79 scoped_refptr<const Extension> webstore_extension(
80 CreateTestExtension(extensions::kWebStoreAppId)); 80 CreateTestExtension(extensions::kWebStoreAppId));
81 RendererExtensionRegistry::Get()->Insert(webstore_extension.get()); 81 RendererExtensionRegistry::Get()->Insert(webstore_extension.get());
82 extension_dispatcher_->OnActivateExtension(extensions::kWebStoreAppId); 82 extension_dispatcher_->OnActivateExtension(extensions::kWebStoreAppId);
83 EXPECT_FALSE(extension->permissions_data()->CanAccessPage( 83 EXPECT_FALSE(extension->permissions_data()->CanAccessPage(
84 extension.get(), kAnyUrl, -1, &error)) 84 extension.get(), kAnyUrl, -1, &error))
85 << error; 85 << error;
86 } 86 }
87 87
88 } // namespace extensions 88 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698