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

Side by Side Diff: chrome/test/base/test_navigation_observer.cc

Issue 8586009: Allow WebUI Tests to use preLoad in HtmlDialogUI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add conditional set_preload_ info. Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/test/test_navigation_observer.h" 5 #include "chrome/test/base/test_navigation_observer.h"
6 6
7 #include "chrome/test/base/js_injection_ready_observer.h"
7 #include "chrome/test/base/ui_test_utils.h" 8 #include "chrome/test/base/ui_test_utils.h"
8 #include "content/browser/renderer_host/render_view_host_observer.h" 9 #include "content/browser/renderer_host/render_view_host_observer.h"
9 #include "content/public/browser/notification_service.h" 10 #include "content/public/browser/notification_service.h"
10 #include "content/public/browser/notification_types.h" 11 #include "content/public/browser/notification_types.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 // This class observes |rvh| and calls OnJsInjectionReady() of 14 // This class observes |rvh| and calls OnJsInjectionReady() of
14 // |js_injection_ready_observer| when the time is right to inject 15 // |js_injection_ready_observer| when the time is right to inject
15 // JavaScript into the page. 16 // JavaScript into the page.
16 class TestNavigationObserver::RVHOSendJS : public RenderViewHostObserver { 17 class TestNavigationObserver::RVHOSendJS : public RenderViewHostObserver {
17 public: 18 public:
18 RVHOSendJS(RenderViewHost* rvh, 19 RVHOSendJS(RenderViewHost* rvh,
19 JsInjectionReadyObserver* js_injection_ready_observer) 20 JsInjectionReadyObserver* js_injection_ready_observer)
20 : RenderViewHostObserver(rvh), 21 : RenderViewHostObserver(rvh),
21 js_injection_ready_observer_(js_injection_ready_observer) { 22 js_injection_ready_observer_(js_injection_ready_observer) {
22 } 23 }
23 24
24 private: 25 private:
25 // RenderViewHostObserver implementation. 26 // RenderViewHostObserver implementation.
26 virtual void RenderViewHostInitialized() OVERRIDE { 27 virtual void RenderViewHostInitialized() OVERRIDE {
27 if (js_injection_ready_observer_) 28 if (js_injection_ready_observer_)
28 js_injection_ready_observer_->OnJsInjectionReady(render_view_host()); 29 js_injection_ready_observer_->OnJsInjectionReady(render_view_host());
29 } 30 }
30 31
31 JsInjectionReadyObserver* js_injection_ready_observer_; 32 JsInjectionReadyObserver* js_injection_ready_observer_;
32 33
33 DISALLOW_COPY_AND_ASSIGN(RVHOSendJS); 34 DISALLOW_COPY_AND_ASSIGN(RVHOSendJS);
34 }; 35 };
35 36
36 TestNavigationObserver::JsInjectionReadyObserver::JsInjectionReadyObserver() {
37 }
38
39 TestNavigationObserver::JsInjectionReadyObserver::~JsInjectionReadyObserver() {
40 }
41
42 TestNavigationObserver::TestNavigationObserver( 37 TestNavigationObserver::TestNavigationObserver(
43 const content::NotificationSource& source, 38 const content::NotificationSource& source,
44 TestNavigationObserver::JsInjectionReadyObserver* 39 JsInjectionReadyObserver* js_injection_ready_observer,
45 js_injection_ready_observer,
46 int number_of_navigations) 40 int number_of_navigations)
47 : navigation_started_(false), 41 : navigation_started_(false),
48 navigations_completed_(0), 42 navigations_completed_(0),
49 number_of_navigations_(number_of_navigations), 43 number_of_navigations_(number_of_navigations),
50 js_injection_ready_observer_(js_injection_ready_observer), 44 js_injection_ready_observer_(js_injection_ready_observer),
51 done_(false), 45 done_(false),
52 running_(false) { 46 running_(false) {
53 // When we need to do javascript injection, register for RVH creation. 47 // When we need to do javascript injection, register for RVH creation.
54 if (js_injection_ready_observer_) { 48 if (js_injection_ready_observer_) {
55 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, 49 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED,
56 content::NotificationService::AllSources()); 50 content::NotificationService::AllSources());
57 } 51 }
58 RegisterAsObserver(source); 52 RegisterAsObserver(source);
59 } 53 }
60 54
61 TestNavigationObserver::~TestNavigationObserver() { 55 TestNavigationObserver::~TestNavigationObserver() {
62 } 56 }
63 57
64 void TestNavigationObserver::WaitForObservation() { 58 void TestNavigationObserver::WaitForObservation() {
65 if (!done_) { 59 if (!done_) {
66 EXPECT_FALSE(running_); 60 EXPECT_FALSE(running_);
67 running_ = true; 61 running_ = true;
68 ui_test_utils::RunMessageLoop(); 62 ui_test_utils::RunMessageLoop();
69 } 63 }
70 } 64 }
71 65
72 TestNavigationObserver::TestNavigationObserver( 66 TestNavigationObserver::TestNavigationObserver(
73 TestNavigationObserver::JsInjectionReadyObserver* 67 JsInjectionReadyObserver*
74 js_injection_ready_observer, 68 js_injection_ready_observer,
75 int number_of_navigations) 69 int number_of_navigations)
76 : navigation_started_(false), 70 : navigation_started_(false),
77 navigations_completed_(0), 71 navigations_completed_(0),
78 number_of_navigations_(number_of_navigations), 72 number_of_navigations_(number_of_navigations),
79 js_injection_ready_observer_(js_injection_ready_observer), 73 js_injection_ready_observer_(js_injection_ready_observer),
80 done_(false), 74 done_(false),
81 running_(false) { 75 running_(false) {
82 // When we need to do javascript injection, register for RVH creation. 76 // When we need to do javascript injection, register for RVH creation.
83 if (js_injection_ready_observer_) { 77 if (js_injection_ready_observer_) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 break; 109 break;
116 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED: 110 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED:
117 rvho_send_js_.reset(new RVHOSendJS( 111 rvho_send_js_.reset(new RVHOSendJS(
118 content::Source<RenderViewHost>(source).ptr(), 112 content::Source<RenderViewHost>(source).ptr(),
119 js_injection_ready_observer_)); 113 js_injection_ready_observer_));
120 break; 114 break;
121 default: 115 default:
122 NOTREACHED(); 116 NOTREACHED();
123 } 117 }
124 } 118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698