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

Side by Side Diff: chrome/test/test_navigation_observer.h

Issue 8586009: Allow WebUI Tests to use preLoad in HtmlDialogUI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed James' comments. 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
« no previous file with comments | « chrome/test/data/webui/test_api.js ('k') | chrome/test/test_navigation_observer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_TEST_TEST_NAVIGATION_OBSERVER_H_
6 #define CHROME_TEST_TEST_NAVIGATION_OBSERVER_H_
7 #pragma once
8
9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_registrar.h"
13
14 class NavigationController;
15 class RenderViewHost;
16
17 // For browser_tests, which run on the UI thread, run a second
18 // MessageLoop and quit when the navigation completes loading. For
19 // WebUI tests that need to inject javascript, construct with a
20 // JsInjectionReadyObserver and this class will call its
21 // OnJsInjectionReady() at the appropriate time.
22 class TestNavigationObserver : public content::NotificationObserver {
23 public:
24 class RVHOSendJS;
25
26 // Interface to notify when JavaScript injection is possible.
27 class JsInjectionReadyObserver {
28 public:
29 JsInjectionReadyObserver();
30 virtual ~JsInjectionReadyObserver();
31
32 // Called to indicate page entry committed and ready for JavaScript
33 // injection.
34 virtual void OnJsInjectionReady(RenderViewHost* render_view_host) = 0;
35 };
36
37 // Create and register a new TestNavigationObserver against the
38 // |controller|. When |js_injection_ready_observer| is non-null, notify with
39 // OnEntryCommitted() after |number_of_navigations| navigations.
40 // Note: |js_injection_ready_observer| is owned by the caller and should be
41 // valid until this class is destroyed.
42 TestNavigationObserver(const content::NotificationSource& source,
43 JsInjectionReadyObserver* js_injection_ready_observer,
44 int number_of_navigations);
45
46 virtual ~TestNavigationObserver();
47
48 // Run the UI message loop until |done_| becomes true.
49 void WaitForObservation();
50
51 protected:
52 // Note: |js_injection_ready_observer| is owned by the caller and should be
53 // valid until this class is destroyed. Subclasses using this constructor MUST
54 // call RegisterAsObserver when a NavigationController becomes available.
55 explicit TestNavigationObserver(
56 JsInjectionReadyObserver* js_injection_ready_observer,
57 int number_of_navigations);
58
59 // Register this TestNavigationObserver as an observer of the |source|.
60 void RegisterAsObserver(const content::NotificationSource& source);
61
62 private:
63 // content::NotificationObserver:
64 virtual void Observe(int type, const content::NotificationSource& source,
65 const content::NotificationDetails& details) OVERRIDE;
66
67 content::NotificationRegistrar registrar_;
68
69 // If true the navigation has started.
70 bool navigation_started_;
71
72 // The number of navigations that have been completed.
73 int navigations_completed_;
74
75 // The number of navigations to wait for.
76 int number_of_navigations_;
77
78 // Observer to take some action when the page is ready for JavaScript
79 // injection.
80 JsInjectionReadyObserver* js_injection_ready_observer_;
81
82 // |done_| will get set when this object observes a TabStripModel event.
83 bool done_;
84
85 // |running_| will be true during WaitForObservation until |done_| is true.
86 bool running_;
87
88 // |rvho_send_js_| will hold a RenderViewHostObserver subclass to allow
89 // JavaScript injection at the appropriate time.
90 scoped_ptr<RVHOSendJS> rvho_send_js_;
91
92 DISALLOW_COPY_AND_ASSIGN(TestNavigationObserver);
93 };
94
95 #endif // CHROME_TEST_TEST_NAVIGATION_OBSERVER_H_
OLDNEW
« no previous file with comments | « chrome/test/data/webui/test_api.js ('k') | chrome/test/test_navigation_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698