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

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

Issue 1047943002: Cache --whitelisted-extension-id in SimpleFeature. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update tests that fail on memory bots. 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
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 "chrome/browser/extensions/test_extension_environment.h" 5 #include "chrome/browser/extensions/test_extension_environment.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/test_extension_system.h" 12 #include "chrome/browser/extensions/test_extension_system.h"
13 #include "chrome/browser/sessions/session_tab_helper.h" 13 #include "chrome/browser/sessions/session_tab_helper.h"
14 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
15 #include "content/public/test/test_utils.h" 15 #include "content/public/test/test_utils.h"
16 #include "content/public/test/web_contents_tester.h" 16 #include "content/public/test/web_contents_tester.h"
17 #include "extensions/common/extension.h" 17 #include "extensions/common/extension.h"
18 #include "extensions/common/extension_builder.h" 18 #include "extensions/common/extension_builder.h"
19 #include "extensions/common/value_builder.h" 19 #include "extensions/common/value_builder.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 21
22 #if defined(USE_AURA) 22 #if defined(USE_AURA)
23 #include "ui/aura/env.h" 23 #include "ui/aura/env.h"
24 #endif 24 #endif
25 25
26 namespace extensions { 26 namespace extensions {
27 27
28 using content::BrowserThread; 28 using content::BrowserThread;
29 29
30 namespace {
31
32 scoped_ptr<base::DictionaryValue> MakeExtensionManifest(
33 const base::Value& manifest_extra) {
34 scoped_ptr<base::DictionaryValue> manifest = DictionaryBuilder()
35 .Set("name", "Extension")
36 .Set("version", "1.0")
37 .Set("manifest_version", 2)
38 .Build();
39 const base::DictionaryValue* manifest_extra_dict;
40 if (manifest_extra.GetAsDictionary(&manifest_extra_dict)) {
41 manifest->MergeDictionary(manifest_extra_dict);
42 } else {
43 std::string manifest_json;
44 base::JSONWriter::Write(&manifest_extra, &manifest_json);
45 ADD_FAILURE() << "Expected dictionary; got \"" << manifest_json << "\"";
46 }
47 return manifest;
48 }
49
50 } // namespace
51
30 TestExtensionEnvironment::TestExtensionEnvironment() 52 TestExtensionEnvironment::TestExtensionEnvironment()
31 : profile_(new TestingProfile), 53 : profile_(new TestingProfile),
32 extension_service_(NULL), 54 extension_service_(NULL),
33 extension_prefs_(NULL) { 55 extension_prefs_(NULL) {
34 #if defined(USE_AURA) 56 #if defined(USE_AURA)
35 aura::Env::CreateInstance(true); 57 aura::Env::CreateInstance(true);
36 #endif 58 #endif
37 } 59 }
38 60
39 TestExtensionEnvironment::~TestExtensionEnvironment() { 61 TestExtensionEnvironment::~TestExtensionEnvironment() {
(...skipping 21 matching lines...) Expand all
61 ExtensionPrefs* TestExtensionEnvironment::GetExtensionPrefs() { 83 ExtensionPrefs* TestExtensionEnvironment::GetExtensionPrefs() {
62 if (extension_prefs_ == NULL) { 84 if (extension_prefs_ == NULL) {
63 extension_prefs_ = GetExtensionSystem()->CreateExtensionPrefs( 85 extension_prefs_ = GetExtensionSystem()->CreateExtensionPrefs(
64 base::CommandLine::ForCurrentProcess(), base::FilePath()); 86 base::CommandLine::ForCurrentProcess(), base::FilePath());
65 } 87 }
66 return extension_prefs_; 88 return extension_prefs_;
67 } 89 }
68 90
69 const Extension* TestExtensionEnvironment::MakeExtension( 91 const Extension* TestExtensionEnvironment::MakeExtension(
70 const base::Value& manifest_extra) { 92 const base::Value& manifest_extra) {
71 scoped_ptr<base::DictionaryValue> manifest = DictionaryBuilder() 93 scoped_ptr<base::DictionaryValue> manifest =
72 .Set("name", "Extension") 94 MakeExtensionManifest(manifest_extra);
73 .Set("version", "1.0")
74 .Set("manifest_version", 2)
75 .Build();
76 const base::DictionaryValue* manifest_extra_dict;
77 if (manifest_extra.GetAsDictionary(&manifest_extra_dict)) {
78 manifest->MergeDictionary(manifest_extra_dict);
79 } else {
80 std::string manifest_json;
81 base::JSONWriter::Write(&manifest_extra, &manifest_json);
82 ADD_FAILURE() << "Expected dictionary; got \"" << manifest_json << "\"";
83 }
84
85 scoped_refptr<Extension> result = 95 scoped_refptr<Extension> result =
86 ExtensionBuilder().SetManifest(manifest.Pass()).Build(); 96 ExtensionBuilder().SetManifest(manifest.Pass()).Build();
87 GetExtensionService()->AddExtension(result.get()); 97 GetExtensionService()->AddExtension(result.get());
88 return result.get(); 98 return result.get();
89 } 99 }
90 100
101 const Extension* TestExtensionEnvironment::MakeExtension(
102 const base::Value& manifest_extra,
103 const std::string& id) {
104 scoped_ptr<base::DictionaryValue> manifest =
105 MakeExtensionManifest(manifest_extra);
106 scoped_refptr<Extension> result =
107 ExtensionBuilder().SetManifest(manifest.Pass()).SetID(id).Build();
108 GetExtensionService()->AddExtension(result.get());
109 return result.get();
110 }
111
91 scoped_ptr<content::WebContents> TestExtensionEnvironment::MakeTab() const { 112 scoped_ptr<content::WebContents> TestExtensionEnvironment::MakeTab() const {
92 scoped_ptr<content::WebContents> contents( 113 scoped_ptr<content::WebContents> contents(
93 content::WebContentsTester::CreateTestWebContents(profile(), NULL)); 114 content::WebContentsTester::CreateTestWebContents(profile(), NULL));
94 // Create a tab id. 115 // Create a tab id.
95 SessionTabHelper::CreateForWebContents(contents.get()); 116 SessionTabHelper::CreateForWebContents(contents.get());
96 return contents.Pass(); 117 return contents.Pass();
97 } 118 }
98 119
99 } // namespace extensions 120 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698