IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / public / test / test_navigation_observer.h
blobf6e5e41b71dfb8b5039d8a820c6b01a79d4e6a9f
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_PUBLIC_TEST_TEST_NAVIGATION_OBSERVER_H_
6 #define CONTENT_PUBLIC_TEST_TEST_NAVIGATION_OBSERVER_H_
8 #include <set>
10 #include "base/callback.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "content/public/test/test_utils.h"
15 namespace content {
16 class WebContents;
17 struct LoadCommittedDetails;
19 // For browser_tests, which run on the UI thread, run a second
20 // MessageLoop and quit when the navigation completes loading.
21 class TestNavigationObserver {
22 public:
23 // Create and register a new TestNavigationObserver against the
24 // |web_contents|.
25 TestNavigationObserver(WebContents* web_contents,
26 int number_of_navigations);
27 // Like above but waits for one navigation.
28 explicit TestNavigationObserver(WebContents* web_contents);
30 virtual ~TestNavigationObserver();
32 // Runs a nested message loop and blocks until the expected number of
33 // navigations are complete.
34 void Wait();
36 // Start/stop watching newly created WebContents.
37 void StartWatchingNewWebContents();
38 void StopWatchingNewWebContents();
40 protected:
41 // Register this TestNavigationObserver as an observer of the |web_contents|.
42 void RegisterAsObserver(WebContents* web_contents);
44 private:
45 class TestWebContentsObserver;
47 // Callbacks for WebContents-related events.
48 void OnWebContentsCreated(WebContents* web_contents);
49 void OnWebContentsDestroyed(TestWebContentsObserver* observer,
50 WebContents* web_contents);
51 void OnNavigationEntryCommitted(
52 TestWebContentsObserver* observer,
53 WebContents* web_contents,
54 const LoadCommittedDetails& load_details);
55 void OnDidStartLoading(WebContents* web_contents);
56 void OnDidStopLoading(WebContents* web_contents);
58 // If true the navigation has started.
59 bool navigation_started_;
61 // The number of navigations that have been completed.
62 int navigations_completed_;
64 // The number of navigations to wait for.
65 int number_of_navigations_;
67 // The MessageLoopRunner used to spin the message loop.
68 scoped_refptr<MessageLoopRunner> message_loop_runner_;
70 // Callback invoked on WebContents creation.
71 base::Callback<void(WebContents*)> web_contents_created_callback_;
73 // Living TestWebContentsObservers created by this observer.
74 std::set<TestWebContentsObserver*> web_contents_observers_;
76 DISALLOW_COPY_AND_ASSIGN(TestNavigationObserver);
79 } // namespace content
81 #endif // CONTENT_PUBLIC_TEST_TEST_NAVIGATION_OBSERVER_H_