OLD | NEW |
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/api/tabs/tabs_constants.h" |
13 #include "chrome/browser/extensions/extension_function.h" | 13 #include "chrome/browser/extensions/extension_function.h" |
14 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 14 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
17 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
20 using content::WebContents; | 20 using content::WebContents; |
21 using extensions::Extension; | 21 using extensions::Extension; |
| 22 using extensions::Manifest; |
22 namespace keys = extensions::tabs_constants; | 23 namespace keys = extensions::tabs_constants; |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 class TestFunctionDispatcherDelegate | 27 class TestFunctionDispatcherDelegate |
27 : public ExtensionFunctionDispatcher::Delegate { | 28 : public ExtensionFunctionDispatcher::Delegate { |
28 public: | 29 public: |
29 explicit TestFunctionDispatcherDelegate(Browser* browser) : | 30 explicit TestFunctionDispatcherDelegate(Browser* browser) : |
30 browser_(browser) {} | 31 browser_(browser) {} |
31 virtual ~TestFunctionDispatcherDelegate() {} | 32 virtual ~TestFunctionDispatcherDelegate() {} |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 return static_cast<base::DictionaryValue*>(val); | 96 return static_cast<base::DictionaryValue*>(val); |
96 } | 97 } |
97 | 98 |
98 base::ListValue* ToList(base::Value* val) { | 99 base::ListValue* ToList(base::Value* val) { |
99 EXPECT_TRUE(val); | 100 EXPECT_TRUE(val); |
100 EXPECT_EQ(base::Value::TYPE_LIST, val->GetType()); | 101 EXPECT_EQ(base::Value::TYPE_LIST, val->GetType()); |
101 return static_cast<base::ListValue*>(val); | 102 return static_cast<base::ListValue*>(val); |
102 } | 103 } |
103 | 104 |
104 scoped_refptr<Extension> CreateEmptyExtension() { | 105 scoped_refptr<Extension> CreateEmptyExtension() { |
105 return CreateEmptyExtensionWithLocation(Extension::INTERNAL); | 106 return CreateEmptyExtensionWithLocation(Manifest::INTERNAL); |
106 } | 107 } |
107 | 108 |
108 scoped_refptr<Extension> CreateEmptyExtensionWithLocation( | 109 scoped_refptr<Extension> CreateEmptyExtensionWithLocation( |
109 Extension::Location location) { | 110 Manifest::Location location) { |
110 scoped_ptr<base::DictionaryValue> test_extension_value( | 111 scoped_ptr<base::DictionaryValue> test_extension_value( |
111 ParseDictionary("{\"name\": \"Test\", \"version\": \"1.0\"}")); | 112 ParseDictionary("{\"name\": \"Test\", \"version\": \"1.0\"}")); |
112 return CreateExtension(location, test_extension_value.get(), std::string()); | 113 return CreateExtension(location, test_extension_value.get(), std::string()); |
113 } | 114 } |
114 | 115 |
115 scoped_refptr<Extension> CreateEmptyExtension( | 116 scoped_refptr<Extension> CreateEmptyExtension( |
116 const std::string& id_input) { | 117 const std::string& id_input) { |
117 scoped_ptr<base::DictionaryValue> test_extension_value( | 118 scoped_ptr<base::DictionaryValue> test_extension_value( |
118 ParseDictionary("{\"name\": \"Test\", \"version\": \"1.0\"}")); | 119 ParseDictionary("{\"name\": \"Test\", \"version\": \"1.0\"}")); |
119 return CreateExtension(Extension::INTERNAL, test_extension_value.get(), | 120 return CreateExtension(Manifest::INTERNAL, test_extension_value.get(), |
120 id_input); | 121 id_input); |
121 } | 122 } |
122 | 123 |
123 scoped_refptr<Extension> CreateExtension( | 124 scoped_refptr<Extension> CreateExtension( |
124 base::DictionaryValue* test_extension_value) { | 125 base::DictionaryValue* test_extension_value) { |
125 return CreateExtension(Extension::INTERNAL, test_extension_value, | 126 return CreateExtension(Manifest::INTERNAL, test_extension_value, |
126 std::string()); | 127 std::string()); |
127 } | 128 } |
128 | 129 |
129 scoped_refptr<Extension> CreateExtension( | 130 scoped_refptr<Extension> CreateExtension( |
130 Extension::Location location, | 131 Manifest::Location location, |
131 base::DictionaryValue* test_extension_value, | 132 base::DictionaryValue* test_extension_value, |
132 const std::string& id_input) { | 133 const std::string& id_input) { |
133 std::string error; | 134 std::string error; |
134 const FilePath test_extension_path; | 135 const FilePath test_extension_path; |
135 std::string id; | 136 std::string id; |
136 if (!id_input.empty()) | 137 if (!id_input.empty()) |
137 CHECK(Extension::GenerateId(id_input, &id)); | 138 CHECK(Extension::GenerateId(id_input, &id)); |
138 scoped_refptr<Extension> extension(Extension::Create( | 139 scoped_refptr<Extension> extension(Extension::Create( |
139 test_extension_path, | 140 test_extension_path, |
140 location, | 141 location, |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 if (!response_delegate.HasResponse()) { | 262 if (!response_delegate.HasResponse()) { |
262 response_delegate.set_should_post_quit(true); | 263 response_delegate.set_should_post_quit(true); |
263 content::RunMessageLoop(); | 264 content::RunMessageLoop(); |
264 } | 265 } |
265 | 266 |
266 EXPECT_TRUE(response_delegate.HasResponse()); | 267 EXPECT_TRUE(response_delegate.HasResponse()); |
267 return response_delegate.GetResponse(); | 268 return response_delegate.GetResponse(); |
268 } | 269 } |
269 | 270 |
270 } // namespace extension_function_test_utils | 271 } // namespace extension_function_test_utils |
OLD | NEW |