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

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

Issue 10697017: Tabs Extension: Implementation of tabs.duplicate api. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
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/extension_function_test_utils.h" 5 #include "chrome/browser/extensions/extension_function_test_utils.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
12 #include "chrome/browser/extensions/extension_function.h" 13 #include "chrome/browser/extensions/extension_function.h"
13 #include "chrome/browser/extensions/extension_function_dispatcher.h" 14 #include "chrome/browser/extensions/extension_function_dispatcher.h"
14 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
15 #include "chrome/common/extensions/extension.h" 16 #include "chrome/common/extensions/extension.h"
16 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 using content::WebContents; 20 using content::WebContents;
20 using extensions::Extension; 21 using extensions::Extension;
22 namespace keys = extensions::tabs_constants;
21 23
22 namespace { 24 namespace {
23 25
24 class TestFunctionDispatcherDelegate 26 class TestFunctionDispatcherDelegate
25 : public ExtensionFunctionDispatcher::Delegate { 27 : public ExtensionFunctionDispatcher::Delegate {
26 public: 28 public:
27 explicit TestFunctionDispatcherDelegate(Browser* browser) : 29 explicit TestFunctionDispatcherDelegate(Browser* browser) :
28 browser_(browser) {} 30 browser_(browser) {}
29 virtual ~TestFunctionDispatcherDelegate() {} 31 virtual ~TestFunctionDispatcherDelegate() {}
30 32
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 EXPECT_EQ(base::Value::TYPE_LIST, val->GetType()); 100 EXPECT_EQ(base::Value::TYPE_LIST, val->GetType());
99 return static_cast<base::ListValue*>(val); 101 return static_cast<base::ListValue*>(val);
100 } 102 }
101 103
102 scoped_refptr<Extension> CreateEmptyExtension() { 104 scoped_refptr<Extension> CreateEmptyExtension() {
103 return CreateEmptyExtensionWithLocation(Extension::INTERNAL); 105 return CreateEmptyExtensionWithLocation(Extension::INTERNAL);
104 } 106 }
105 107
106 scoped_refptr<Extension> CreateEmptyExtensionWithLocation( 108 scoped_refptr<Extension> CreateEmptyExtensionWithLocation(
107 Extension::Location location) { 109 Extension::Location location) {
110 scoped_ptr<base::DictionaryValue> test_extension_value(
111 ParseDictionary("{\"name\": \"Test\", \"version\": \"1.0\"}"));
112 return CreateExtension(location, test_extension_value.get());
113 }
114
115 scoped_refptr<Extension> CreateExtension(
116 base::DictionaryValue* test_extension_value) {
117 return CreateExtension(Extension::INTERNAL, test_extension_value);
118 }
119
120 scoped_refptr<Extension> CreateExtension(
121 Extension::Location location,
122 base::DictionaryValue* test_extension_value) {
108 std::string error; 123 std::string error;
109 const FilePath test_extension_path; 124 const FilePath test_extension_path;
110 scoped_ptr<base::DictionaryValue> test_extension_value(
111 ParseDictionary("{\"name\": \"Test\", \"version\": \"1.0\"}"));
112 scoped_refptr<Extension> extension(Extension::Create( 125 scoped_refptr<Extension> extension(Extension::Create(
113 test_extension_path, 126 test_extension_path,
114 location, 127 location,
115 *test_extension_value.get(), 128 *test_extension_value,
116 Extension::NO_FLAGS, 129 Extension::NO_FLAGS,
117 &error)); 130 &error));
118 EXPECT_TRUE(error.empty()) << "Could not parse test extension " << error; 131 EXPECT_TRUE(error.empty()) << "Could not parse test extension " << error;
119 return extension; 132 return extension;
120 } 133 }
121 134
135 bool HasPrivacySensitiveFields(base::DictionaryValue* val) {
136 std::string result;
137 if (val->GetString(keys::kUrlKey, &result) ||
138 val->GetString(keys::kTitleKey, &result) ||
139 val->GetString(keys::kFaviconUrlKey, &result))
140 return true;
141 return false;
142 }
143
122 std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, 144 std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function,
123 const std::string& args, 145 const std::string& args,
124 Browser* browser) { 146 Browser* browser) {
125 return RunFunctionAndReturnError(function, args, browser, NONE); 147 return RunFunctionAndReturnError(function, args, browser, NONE);
126 } 148 }
127 std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, 149 std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function,
128 const std::string& args, 150 const std::string& args,
129 Browser* browser, 151 Browser* browser,
130 RunFunctionFlags flags) { 152 RunFunctionFlags flags) {
131 scoped_refptr<ExtensionFunction> function_owner(function); 153 scoped_refptr<ExtensionFunction> function_owner(function);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 if (!response_delegate.HasResponse()) { 247 if (!response_delegate.HasResponse()) {
226 response_delegate.set_should_post_quit(true); 248 response_delegate.set_should_post_quit(true);
227 content::RunMessageLoop(); 249 content::RunMessageLoop();
228 } 250 }
229 251
230 EXPECT_TRUE(response_delegate.HasResponse()); 252 EXPECT_TRUE(response_delegate.HasResponse());
231 return response_delegate.GetResponse(); 253 return response_delegate.GetResponse();
232 } 254 }
233 255
234 } // namespace extension_function_test_utils 256 } // namespace extension_function_test_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698