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

Side by Side Diff: extensions/browser/policy_check_unittest.cc

Issue 2802433004: ExtensionsTest: Move initialization to SetUp and avoid potential UAF. (Closed)
Patch Set: Avoid UAF. Created 3 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "extensions/browser/policy_check.h" 5 #include "extensions/browser/policy_check.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 ManagementPolicy* management_policy() override { return &management_policy_; } 59 ManagementPolicy* management_policy() override { return &management_policy_; }
60 60
61 private: 61 private:
62 ManagementPolicy management_policy_; 62 ManagementPolicy management_policy_;
63 }; 63 };
64 64
65 } // namespace 65 } // namespace
66 66
67 class PolicyCheckTest : public ExtensionsTest { 67 class PolicyCheckTest : public ExtensionsTest {
68 public: 68 public:
69 PolicyCheckTest() { 69 PolicyCheckTest() {}
70 // Replace the MockExtensionSystemFactory set by ExtensionsTest.
71 extensions_browser_client()->set_extension_system_factory(&factory_);
72 }
73 70
74 ~PolicyCheckTest() override {} 71 ~PolicyCheckTest() override {}
75 72
76 void SetUp() override { 73 void SetUp() override {
77 ExtensionsTest::SetUp(); 74 ExtensionsTest::SetUp();
78 75
76 // Replace the MockExtensionSystemFactory set by ExtensionsTest.
77 extensions_browser_client()->set_extension_system_factory(&factory_);
78
79 base::DictionaryValue manifest_dict; 79 base::DictionaryValue manifest_dict;
80 manifest_dict.SetString("name", "dummy name"); 80 manifest_dict.SetString("name", "dummy name");
81 manifest_dict.SetString("version", "1"); 81 manifest_dict.SetString("version", "1");
82 std::string error; 82 std::string error;
83 83
84 extension_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, 84 extension_ = Extension::Create(base::FilePath(), Manifest::UNPACKED,
85 manifest_dict, Extension::NO_FLAGS, &error); 85 manifest_dict, Extension::NO_FLAGS, &error);
86 EXPECT_TRUE(extension_.get()) << error; 86 EXPECT_TRUE(extension_.get()) << error;
87 } 87 }
88 88
(...skipping 24 matching lines...) Expand all
113 PolicyCheck policy_check(browser_context(), extension_); 113 PolicyCheck policy_check(browser_context(), extension_);
114 runner_.Run(&policy_check); 114 runner_.Run(&policy_check);
115 EXPECT_TRUE(runner_.called()); 115 EXPECT_TRUE(runner_.called());
116 EXPECT_THAT(runner_.errors(), testing::UnorderedElementsAre( 116 EXPECT_THAT(runner_.errors(), testing::UnorderedElementsAre(
117 PreloadCheck::DISALLOWED_BY_POLICY)); 117 PreloadCheck::DISALLOWED_BY_POLICY));
118 EXPECT_EQ(base::ASCIIToUTF16(kDummyPolicyError), 118 EXPECT_EQ(base::ASCIIToUTF16(kDummyPolicyError),
119 policy_check.GetErrorMessage()); 119 policy_check.GetErrorMessage());
120 } 120 }
121 121
122 } // namespace extensions 122 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698