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

Side by Side Diff: chrome/browser/ui/webui/web_ui_browsertest.cc

Issue 11885021: Don't derive from ChromeURLDataManager::DataSource, and instead have these classes implement a dele… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: nits Created 7 years, 11 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/ui/webui/web_ui_browsertest.h" 5 #include "chrome/browser/ui/webui/web_ui_browsertest.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/ui/browser_navigator.h" 21 #include "chrome/browser/ui/browser_navigator.h"
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" 22 #include "chrome/browser/ui/tabs/tab_strip_model.h"
23 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 23 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
24 #include "chrome/browser/ui/webui/test_chrome_web_ui_controller_factory.h" 24 #include "chrome/browser/ui/webui/test_chrome_web_ui_controller_factory.h"
25 #include "chrome/browser/ui/webui/web_ui_test_handler.h" 25 #include "chrome/browser/ui/webui/web_ui_test_handler.h"
26 #include "chrome/common/chrome_paths.h" 26 #include "chrome/common/chrome_paths.h"
27 #include "chrome/common/url_constants.h" 27 #include "chrome/common/url_constants.h"
28 #include "chrome/test/base/test_tab_strip_model_observer.h" 28 #include "chrome/test/base/test_tab_strip_model_observer.h"
29 #include "chrome/test/base/ui_test_utils.h" 29 #include "chrome/test/base/ui_test_utils.h"
30 #include "content/public/browser/navigation_controller.h" 30 #include "content/public/browser/navigation_controller.h"
31 #include "content/public/browser/url_data_source_delegate.h"
31 #include "content/public/browser/web_contents.h" 32 #include "content/public/browser/web_contents.h"
32 #include "content/public/browser/web_ui_controller.h" 33 #include "content/public/browser/web_ui_controller.h"
33 #include "content/public/browser/web_ui_message_handler.h" 34 #include "content/public/browser/web_ui_message_handler.h"
34 #include "net/base/net_util.h" 35 #include "net/base/net_util.h"
35 #include "testing/gmock/include/gmock/gmock.h" 36 #include "testing/gmock/include/gmock/gmock.h"
36 #include "testing/gtest/include/gtest/gtest-spi.h" 37 #include "testing/gtest/include/gtest/gtest-spi.h"
37 #include "ui/base/resource/resource_bundle.h" 38 #include "ui/base/resource/resource_bundle.h"
38 #include "ui/base/resource/resource_handle.h" 39 #include "ui/base/resource/resource_handle.h"
39 40
40 using content::NavigationController; 41 using content::NavigationController;
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 const std::string& preload_test_name) { 261 const std::string& preload_test_name) {
261 preload_test_name_ = preload_test_name; 262 preload_test_name_ = preload_test_name;
262 } 263 }
263 264
264 namespace { 265 namespace {
265 266
266 // DataSource for the dummy URL. If no data source is provided then an error 267 // DataSource for the dummy URL. If no data source is provided then an error
267 // page is shown. While this doesn't matter for most tests, without it, 268 // page is shown. While this doesn't matter for most tests, without it,
268 // navigation to different anchors cannot be listened to (via the hashchange 269 // navigation to different anchors cannot be listened to (via the hashchange
269 // event). 270 // event).
270 class MockWebUIDataSource : public ChromeURLDataManager::DataSource { 271 class MockWebUIDataSource : public content::URLDataSourceDelegate {
271 public: 272 public:
272 MockWebUIDataSource() 273 MockWebUIDataSource() {}
273 : ChromeURLDataManager::DataSource("dummyurl", MessageLoop::current()) {}
274 274
275 private: 275 private:
276 virtual ~MockWebUIDataSource() {} 276 virtual ~MockWebUIDataSource() {}
277 277
278 virtual std::string GetSource() OVERRIDE {
279 return "dummyurl";
280 }
281
278 virtual void StartDataRequest(const std::string& path, 282 virtual void StartDataRequest(const std::string& path,
279 bool is_incognito, 283 bool is_incognito,
280 int request_id) OVERRIDE { 284 int request_id) OVERRIDE {
281 std::string dummy_html = "<html><body>Dummy</body></html>"; 285 std::string dummy_html = "<html><body>Dummy</body></html>";
282 scoped_refptr<base::RefCountedString> response = 286 scoped_refptr<base::RefCountedString> response =
283 base::RefCountedString::TakeString(&dummy_html); 287 base::RefCountedString::TakeString(&dummy_html);
284 SendResponse(request_id, response); 288 url_data_source()->SendResponse(request_id, response);
285 } 289 }
286 290
287 std::string GetMimeType(const std::string& path) const OVERRIDE { 291 std::string GetMimeType(const std::string& path) const OVERRIDE {
288 return "text/html"; 292 return "text/html";
289 } 293 }
290 294
291 DISALLOW_COPY_AND_ASSIGN(MockWebUIDataSource); 295 DISALLOW_COPY_AND_ASSIGN(MockWebUIDataSource);
292 }; 296 };
293 297
294 // WebUIProvider to allow attaching the DataSource for the dummy URL when 298 // WebUIProvider to allow attaching the DataSource for the dummy URL when
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 // testDone directly and expect pass result. 711 // testDone directly and expect pass result.
708 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { 712 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) {
709 ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); 713 ASSERT_TRUE(RunJavascriptAsyncTest("testDone"));
710 } 714 }
711 715
712 // Test that calling testDone during RunJavascriptTest still completes when 716 // Test that calling testDone during RunJavascriptTest still completes when
713 // waiting for async result. 717 // waiting for async result.
714 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { 718 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) {
715 ASSERT_TRUE(RunJavascriptTest("testDone")); 719 ASSERT_TRUE(RunJavascriptTest("testDone"));
716 } 720 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698