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/extension_protocols_unittest.cc

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged ToT Created 7 years, 6 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 <string> 5 #include <string>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/extensions/extension_info_map.h" 11 #include "chrome/browser/extensions/extension_info_map.h"
12 #include "chrome/browser/extensions/extension_protocols.h" 12 #include "chrome/browser/extensions/extension_protocols.h"
13 #include "chrome/common/chrome_paths.h" 13 #include "chrome/common/chrome_paths.h"
14 #include "chrome/common/extensions/extension.h" 14 #include "chrome/common/extensions/extension.h"
15 #include "chrome/common/extensions/extension_manifest_constants.h" 15 #include "chrome/common/extensions/extension_manifest_constants.h"
16 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
17 #include "content/public/browser/resource_request_info.h" 17 #include "content/public/browser/resource_request_info.h"
18 #include "content/public/test/mock_resource_context.h" 18 #include "content/public/test/mock_resource_context.h"
19 #include "content/public/test/test_browser_thread.h" 19 #include "content/public/test/test_browser_thread_bundle.h"
20 #include "extensions/common/constants.h" 20 #include "extensions/common/constants.h"
21 #include "net/url_request/url_request.h" 21 #include "net/url_request/url_request.h"
22 #include "net/url_request/url_request_job_factory_impl.h" 22 #include "net/url_request/url_request_job_factory_impl.h"
23 #include "net/url_request/url_request_status.h" 23 #include "net/url_request/url_request_status.h"
24 #include "net/url_request/url_request_test_util.h" 24 #include "net/url_request/url_request_test_util.h"
25 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 26
27 using content::BrowserThread;
28
29 namespace extensions { 27 namespace extensions {
30 28
31 scoped_refptr<Extension> CreateTestExtension(const std::string& name, 29 scoped_refptr<Extension> CreateTestExtension(const std::string& name,
32 bool incognito_split_mode) { 30 bool incognito_split_mode) {
33 DictionaryValue manifest; 31 DictionaryValue manifest;
34 manifest.SetString("name", name); 32 manifest.SetString("name", name);
35 manifest.SetString("version", "1"); 33 manifest.SetString("version", "1");
36 manifest.SetString("incognito", incognito_split_mode ? "split" : "spanning"); 34 manifest.SetString("incognito", incognito_split_mode ? "split" : "spanning");
37 35
38 base::FilePath path; 36 base::FilePath path;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 scoped_refptr<Extension> extension( 79 scoped_refptr<Extension> extension(
82 Extension::Create(path, Manifest::UNPACKED, manifest, 80 Extension::Create(path, Manifest::UNPACKED, manifest,
83 Extension::NO_FLAGS, &error)); 81 Extension::NO_FLAGS, &error));
84 EXPECT_TRUE(extension.get()) << error; 82 EXPECT_TRUE(extension.get()) << error;
85 return extension; 83 return extension;
86 } 84 }
87 85
88 class ExtensionProtocolTest : public testing::Test { 86 class ExtensionProtocolTest : public testing::Test {
89 public: 87 public:
90 ExtensionProtocolTest() 88 ExtensionProtocolTest()
91 : ui_thread_(BrowserThread::UI, &message_loop_), 89 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {}
92 file_thread_(BrowserThread::FILE, &message_loop_),
93 io_thread_(BrowserThread::IO, &message_loop_) {}
94 90
95 virtual void SetUp() OVERRIDE { 91 virtual void SetUp() OVERRIDE {
96 testing::Test::SetUp(); 92 testing::Test::SetUp();
97 extension_info_map_ = new ExtensionInfoMap(); 93 extension_info_map_ = new ExtensionInfoMap();
98 net::URLRequestContext* request_context = 94 net::URLRequestContext* request_context =
99 resource_context_.GetRequestContext(); 95 resource_context_.GetRequestContext();
100 old_factory_ = request_context->job_factory(); 96 old_factory_ = request_context->job_factory();
101 } 97 }
102 98
103 virtual void TearDown() { 99 virtual void TearDown() {
(...skipping 16 matching lines...) Expand all
120 content::ResourceRequestInfo::AllocateForTesting(request, 116 content::ResourceRequestInfo::AllocateForTesting(request,
121 resource_type, 117 resource_type,
122 &resource_context_, 118 &resource_context_,
123 -1, 119 -1,
124 -1); 120 -1);
125 request->Start(); 121 request->Start();
126 base::MessageLoop::current()->Run(); 122 base::MessageLoop::current()->Run();
127 } 123 }
128 124
129 protected: 125 protected:
130 base::MessageLoopForIO message_loop_; 126 content::TestBrowserThreadBundle thread_bundle_;
131 content::TestBrowserThread ui_thread_;
132 content::TestBrowserThread file_thread_;
133 content::TestBrowserThread io_thread_;
134 scoped_refptr<ExtensionInfoMap> extension_info_map_; 127 scoped_refptr<ExtensionInfoMap> extension_info_map_;
135 net::URLRequestJobFactoryImpl job_factory_; 128 net::URLRequestJobFactoryImpl job_factory_;
136 const net::URLRequestJobFactory* old_factory_; 129 const net::URLRequestJobFactory* old_factory_;
137 net::TestDelegate test_delegate_; 130 net::TestDelegate test_delegate_;
138 content::MockResourceContext resource_context_; 131 content::MockResourceContext resource_context_;
139 }; 132 };
140 133
141 // Tests that making a chrome-extension request in an incognito context is 134 // Tests that making a chrome-extension request in an incognito context is
142 // only allowed under the right circumstances (if the extension is allowed 135 // only allowed under the right circumstances (if the extension is allowed
143 // in incognito, and it's either a non-main-frame request or a split-mode 136 // in incognito, and it's either a non-main-frame request or a split-mode
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 258
266 // We set test.dat as web-accessible, so it should have a CORS header. 259 // We set test.dat as web-accessible, so it should have a CORS header.
267 std::string access_control; 260 std::string access_control;
268 request.GetResponseHeaderByName("Access-Control-Allow-Origin", 261 request.GetResponseHeaderByName("Access-Control-Allow-Origin",
269 &access_control); 262 &access_control);
270 EXPECT_EQ("*", access_control); 263 EXPECT_EQ("*", access_control);
271 } 264 }
272 } 265 }
273 266
274 } // namespace extensions 267 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698