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

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

Issue 1076393002: Revert of Cache --whitelisted-extension-id in SimpleFeature. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
52 TestExtensionEnvironment::TestExtensionEnvironment() 30 TestExtensionEnvironment::TestExtensionEnvironment()
53 : profile_(new TestingProfile), 31 : profile_(new TestingProfile),
54 extension_service_(NULL), 32 extension_service_(NULL),
55 extension_prefs_(NULL) { 33 extension_prefs_(NULL) {
56 #if defined(USE_AURA) 34 #if defined(USE_AURA)
57 aura::Env::CreateInstance(true); 35 aura::Env::CreateInstance(true);
58 #endif 36 #endif
59 } 37 }
60 38
61 TestExtensionEnvironment::~TestExtensionEnvironment() { 39 TestExtensionEnvironment::~TestExtensionEnvironment() {
(...skipping 21 matching lines...) Expand all
83 ExtensionPrefs* TestExtensionEnvironment::GetExtensionPrefs() { 61 ExtensionPrefs* TestExtensionEnvironment::GetExtensionPrefs() {
84 if (extension_prefs_ == NULL) { 62 if (extension_prefs_ == NULL) {
85 extension_prefs_ = GetExtensionSystem()->CreateExtensionPrefs( 63 extension_prefs_ = GetExtensionSystem()->CreateExtensionPrefs(
86 base::CommandLine::ForCurrentProcess(), base::FilePath()); 64 base::CommandLine::ForCurrentProcess(), base::FilePath());
87 } 65 }
88 return extension_prefs_; 66 return extension_prefs_;
89 } 67 }
90 68
91 const Extension* TestExtensionEnvironment::MakeExtension( 69 const Extension* TestExtensionEnvironment::MakeExtension(
92 const base::Value& manifest_extra) { 70 const base::Value& manifest_extra) {
93 scoped_ptr<base::DictionaryValue> manifest = 71 scoped_ptr<base::DictionaryValue> manifest = DictionaryBuilder()
94 MakeExtensionManifest(manifest_extra); 72 .Set("name", "Extension")
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
95 scoped_refptr<Extension> result = 85 scoped_refptr<Extension> result =
96 ExtensionBuilder().SetManifest(manifest.Pass()).Build(); 86 ExtensionBuilder().SetManifest(manifest.Pass()).Build();
97 GetExtensionService()->AddExtension(result.get()); 87 GetExtensionService()->AddExtension(result.get());
98 return result.get(); 88 return result.get();
99 } 89 }
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 90
112 scoped_ptr<content::WebContents> TestExtensionEnvironment::MakeTab() const { 91 scoped_ptr<content::WebContents> TestExtensionEnvironment::MakeTab() const {
113 scoped_ptr<content::WebContents> contents( 92 scoped_ptr<content::WebContents> contents(
114 content::WebContentsTester::CreateTestWebContents(profile(), NULL)); 93 content::WebContentsTester::CreateTestWebContents(profile(), NULL));
115 // Create a tab id. 94 // Create a tab id.
116 SessionTabHelper::CreateForWebContents(contents.get()); 95 SessionTabHelper::CreateForWebContents(contents.get());
117 return contents.Pass(); 96 return contents.Pass();
118 } 97 }
119 98
120 } // namespace extensions 99 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698