| OLD | NEW |
| 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/public/browser/notification_service.h" | 9 #include "content/public/browser/notification_service.h" |
| 9 #include "content/public/browser/notification_types.h" | 10 #include "content/public/browser/notification_types.h" |
| 10 #include "content/public/browser/render_view_host_observer.h" | 11 #include "content/public/browser/render_view_host_observer.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 | 17 class TestNavigationObserver::RVHOSendJS |
| (...skipping 10 matching lines...) Expand all Loading... |
| 27 virtual void RenderViewHostInitialized() OVERRIDE { | 28 virtual void RenderViewHostInitialized() OVERRIDE { |
| 28 if (js_injection_ready_observer_) | 29 if (js_injection_ready_observer_) |
| 29 js_injection_ready_observer_->OnJsInjectionReady(render_view_host()); | 30 js_injection_ready_observer_->OnJsInjectionReady(render_view_host()); |
| 30 } | 31 } |
| 31 | 32 |
| 32 JsInjectionReadyObserver* js_injection_ready_observer_; | 33 JsInjectionReadyObserver* js_injection_ready_observer_; |
| 33 | 34 |
| 34 DISALLOW_COPY_AND_ASSIGN(RVHOSendJS); | 35 DISALLOW_COPY_AND_ASSIGN(RVHOSendJS); |
| 35 }; | 36 }; |
| 36 | 37 |
| 37 TestNavigationObserver::JsInjectionReadyObserver::JsInjectionReadyObserver() { | |
| 38 } | |
| 39 | |
| 40 TestNavigationObserver::JsInjectionReadyObserver::~JsInjectionReadyObserver() { | |
| 41 } | |
| 42 | |
| 43 TestNavigationObserver::TestNavigationObserver( | 38 TestNavigationObserver::TestNavigationObserver( |
| 44 const content::NotificationSource& source, | 39 const content::NotificationSource& source, |
| 45 TestNavigationObserver::JsInjectionReadyObserver* | 40 JsInjectionReadyObserver* js_injection_ready_observer, |
| 46 js_injection_ready_observer, | |
| 47 int number_of_navigations) | 41 int number_of_navigations) |
| 48 : navigation_started_(false), | 42 : navigation_started_(false), |
| 49 navigations_completed_(0), | 43 navigations_completed_(0), |
| 50 number_of_navigations_(number_of_navigations), | 44 number_of_navigations_(number_of_navigations), |
| 51 js_injection_ready_observer_(js_injection_ready_observer), | 45 js_injection_ready_observer_(js_injection_ready_observer), |
| 52 done_(false), | 46 done_(false), |
| 53 running_(false) { | 47 running_(false) { |
| 54 // When we need to do javascript injection, register for RVH creation. | 48 // When we need to do javascript injection, register for RVH creation. |
| 55 if (js_injection_ready_observer_) { | 49 if (js_injection_ready_observer_) { |
| 56 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, | 50 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, |
| 57 content::NotificationService::AllSources()); | 51 content::NotificationService::AllSources()); |
| 58 } | 52 } |
| 59 RegisterAsObserver(source); | 53 RegisterAsObserver(source); |
| 60 } | 54 } |
| 61 | 55 |
| 62 TestNavigationObserver::~TestNavigationObserver() { | 56 TestNavigationObserver::~TestNavigationObserver() { |
| 63 } | 57 } |
| 64 | 58 |
| 65 void TestNavigationObserver::WaitForObservation() { | 59 void TestNavigationObserver::WaitForObservation() { |
| 66 if (!done_) { | 60 if (!done_) { |
| 67 EXPECT_FALSE(running_); | 61 EXPECT_FALSE(running_); |
| 68 running_ = true; | 62 running_ = true; |
| 69 ui_test_utils::RunMessageLoop(); | 63 ui_test_utils::RunMessageLoop(); |
| 70 } | 64 } |
| 71 } | 65 } |
| 72 | 66 |
| 73 TestNavigationObserver::TestNavigationObserver( | 67 TestNavigationObserver::TestNavigationObserver( |
| 74 TestNavigationObserver::JsInjectionReadyObserver* | 68 JsInjectionReadyObserver* |
| 75 js_injection_ready_observer, | 69 js_injection_ready_observer, |
| 76 int number_of_navigations) | 70 int number_of_navigations) |
| 77 : navigation_started_(false), | 71 : navigation_started_(false), |
| 78 navigations_completed_(0), | 72 navigations_completed_(0), |
| 79 number_of_navigations_(number_of_navigations), | 73 number_of_navigations_(number_of_navigations), |
| 80 js_injection_ready_observer_(js_injection_ready_observer), | 74 js_injection_ready_observer_(js_injection_ready_observer), |
| 81 done_(false), | 75 done_(false), |
| 82 running_(false) { | 76 running_(false) { |
| 83 // When we need to do javascript injection, register for RVH creation. | 77 // When we need to do javascript injection, register for RVH creation. |
| 84 if (js_injection_ready_observer_) { | 78 if (js_injection_ready_observer_) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 break; | 110 break; |
| 117 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED: | 111 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED: |
| 118 rvho_send_js_.reset(new RVHOSendJS( | 112 rvho_send_js_.reset(new RVHOSendJS( |
| 119 content::Source<RenderViewHost>(source).ptr(), | 113 content::Source<RenderViewHost>(source).ptr(), |
| 120 js_injection_ready_observer_)); | 114 js_injection_ready_observer_)); |
| 121 break; | 115 break; |
| 122 default: | 116 default: |
| 123 NOTREACHED(); | 117 NOTREACHED(); |
| 124 } | 118 } |
| 125 } | 119 } |
| OLD | NEW |