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

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

Issue 45026: Prevent making real DNS lookups by chrome tests. (Closed)
Patch Set: simplified Created 11 years, 9 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
« no previous file with comments | « no previous file | chrome/browser/net/dns_master_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "base/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/ref_counted.h"
6 #include "chrome/browser/browser.h" 7 #include "chrome/browser/browser.h"
7 #include "chrome/browser/renderer_host/render_view_host.h" 8 #include "chrome/browser/renderer_host/render_view_host.h"
8 #include "chrome/browser/profile.h" 9 #include "chrome/browser/profile.h"
9 #include "chrome/browser/extensions/extension_error_reporter.h" 10 #include "chrome/browser/extensions/extension_error_reporter.h"
10 #include "chrome/browser/extensions/extension_view.h" 11 #include "chrome/browser/extensions/extension_view.h"
11 #include "chrome/browser/extensions/extensions_service.h" 12 #include "chrome/browser/extensions/extensions_service.h"
12 #include "chrome/common/chrome_paths.h" 13 #include "chrome/common/chrome_paths.h"
13 #include "chrome/common/notification_service.h" 14 #include "chrome/common/notification_service.h"
14 #include "chrome/test/in_process_browser_test.h" 15 #include "chrome/test/in_process_browser_test.h"
15 #include "chrome/test/ui_test_utils.h" 16 #include "chrome/test/ui_test_utils.h"
17 #include "net/base/host_resolver_unittest.h"
16 18
17 namespace { 19 namespace {
18 20
19 // How long to wait for the extension to put up a javascript alert before giving 21 // How long to wait for the extension to put up a javascript alert before giving
20 // up. 22 // up.
21 const int kAlertTimeoutMs = 20000; 23 const int kAlertTimeoutMs = 20000;
22 24
23 // How long to wait for the extension to load before giving up. 25 // How long to wait for the extension to load before giving up.
24 const int kLoadTimeoutMs = 10000; 26 const int kLoadTimeoutMs = 10000;
25 27
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } 94 }
93 95
94 NotificationRegistrar registrar_; 96 NotificationRegistrar registrar_;
95 Extension* extension_; 97 Extension* extension_;
96 }; 98 };
97 99
98 } // namespace 100 } // namespace
99 101
100 class ExtensionViewTest : public InProcessBrowserTest { 102 class ExtensionViewTest : public InProcessBrowserTest {
101 public: 103 public:
104 ExtensionViewTest() {
105 host_mapper_ = new net::RuleBasedHostMapper();
106 // TODO(aa): Don't make a real dns lookup here or simulate a failing lookup.
107 // But if it's really needed then remove the TODO.
108 host_mapper_->AllowDirectLookup("*.google.com");
109 scoped_host_mapper_.Init(host_mapper_.get());
110 }
111
102 virtual void SetUp() { 112 virtual void SetUp() {
103 // Initialize the error reporter here, otherwise BrowserMain will create it 113 // Initialize the error reporter here, otherwise BrowserMain will create it
104 // with the wrong MessageLoop. 114 // with the wrong MessageLoop.
105 ExtensionErrorReporter::Init(false); 115 ExtensionErrorReporter::Init(false);
106 116
107 // Use single-process in an attempt to speed it up and make it less flaky. 117 // Use single-process in an attempt to speed it up and make it less flaky.
108 //EnableSingleProcess(); 118 //EnableSingleProcess();
109 119
110 InProcessBrowserTest::SetUp(); 120 InProcessBrowserTest::SetUp();
111 } 121 }
122
123 private:
124 scoped_refptr<net::RuleBasedHostMapper> host_mapper_;
125 net::ScopedHostMapper scoped_host_mapper_;
112 }; 126 };
113 127
114 // Tests that ExtensionView starts an extension process and runs the script 128 // Tests that ExtensionView starts an extension process and runs the script
115 // contained in the extension's "index.html" file. 129 // contained in the extension's "index.html" file.
116 IN_PROC_BROWSER_TEST_F(ExtensionViewTest, Index) { 130 IN_PROC_BROWSER_TEST_F(ExtensionViewTest, Index) {
117 // Create an observer first to be sure we have the notification registered 131 // Create an observer first to be sure we have the notification registered
118 // before it's sent. 132 // before it's sent.
119 ExtensionLoadedObserver observer; 133 ExtensionLoadedObserver observer;
120 134
121 // Get the path to our extension. 135 // Get the path to our extension.
(...skipping 10 matching lines...) Expand all
132 146
133 // Now wait for it to load, and grab a pointer to it. 147 // Now wait for it to load, and grab a pointer to it.
134 Extension* extension = observer.WaitForExtension(); 148 Extension* extension = observer.WaitForExtension();
135 ASSERT_TRUE(extension); 149 ASSERT_TRUE(extension);
136 GURL url = Extension::GetResourceURL(extension->url(), "toolstrip1.html"); 150 GURL url = Extension::GetResourceURL(extension->url(), "toolstrip1.html");
137 151
138 // Start the extension process and wait for it to show a javascript alert. 152 // Start the extension process and wait for it to show a javascript alert.
139 MockExtensionView view(extension, url, profile); 153 MockExtensionView view(extension, url, profile);
140 EXPECT_TRUE(view.got_message()); 154 EXPECT_TRUE(view.got_message());
141 } 155 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/net/dns_master_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698