Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / test / web_contents_observer_sanity_checker.h
blobf7ca421ff487c9a079679d3ea5e95ef8c62288b2
1 // Copyright 2014 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_TEST_WEB_CONTENTS_OBSERVER_SANITY_CHECKER_H_
6 #define CONTENT_TEST_WEB_CONTENTS_OBSERVER_SANITY_CHECKER_H_
8 #include <set>
9 #include <string>
11 #include "base/supports_user_data.h"
12 #include "content/public/browser/web_contents_observer.h"
14 namespace content {
16 // If your test framework enables a ContentBrowserSanityChecker, this sanity
17 // check is automatically installed on all WebContentses during your test.
19 // WebContentsObserverSanityChecker is a WebContentsObserver that sanity-checks
20 // the sequence of observer calls, and CHECK()s if they are inconsistent. These
21 // checks are test-only code designed to find bugs in the implementation of the
22 // content layer by validating the contract between WebContents and its
23 // observers.
25 // For example, WebContentsObserver::RenderFrameCreated announces the existence
26 // of a new RenderFrameHost, so that method call must occur before the
27 // RenderFrameHost is referenced by some other WebContentsObserver method.
28 class WebContentsObserverSanityChecker : public WebContentsObserver,
29 public base::SupportsUserData::Data {
30 public:
31 // Enables these checks on |web_contents|. Usually ContentBrowserSanityChecker
32 // should call this for you.
33 static void Enable(WebContents* web_contents);
35 // WebContentsObserver implementation.
36 void RenderFrameCreated(RenderFrameHost* render_frame_host) override;
37 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override;
38 void RenderFrameForInterstitialPageCreated(
39 RenderFrameHost* render_frame_host) override;
40 void RenderFrameHostChanged(RenderFrameHost* old_host,
41 RenderFrameHost* new_host) override;
42 void FrameDeleted(RenderFrameHost* render_frame_host) override;
43 void DidStartProvisionalLoadForFrame(RenderFrameHost* render_frame_host,
44 const GURL& validated_url,
45 bool is_error_page,
46 bool is_iframe_srcdoc) override;
47 void DidCommitProvisionalLoadForFrame(
48 RenderFrameHost* render_frame_host,
49 const GURL& url,
50 ui::PageTransition transition_type) override;
51 void DidFailProvisionalLoad(RenderFrameHost* render_frame_host,
52 const GURL& validated_url,
53 int error_code,
54 const base::string16& error_description,
55 bool was_ignored_by_handler) override;
56 void DidNavigateMainFrame(const LoadCommittedDetails& details,
57 const FrameNavigateParams& params) override;
58 void DidNavigateAnyFrame(RenderFrameHost* render_frame_host,
59 const LoadCommittedDetails& details,
60 const FrameNavigateParams& params) override;
61 void DocumentAvailableInMainFrame() override;
62 void DocumentOnLoadCompletedInMainFrame() override;
63 void DocumentLoadedInFrame(RenderFrameHost* render_frame_host) override;
64 void DidFinishLoad(RenderFrameHost* render_frame_host,
65 const GURL& validated_url) override;
66 void DidFailLoad(RenderFrameHost* render_frame_host,
67 const GURL& validated_url,
68 int error_code,
69 const base::string16& error_description,
70 bool was_ignored_by_handler) override;
71 void DidGetRedirectForResourceRequest(
72 RenderFrameHost* render_frame_host,
73 const ResourceRedirectDetails& details) override;
74 void DidOpenRequestedURL(WebContents* new_contents,
75 RenderFrameHost* source_render_frame_host,
76 const GURL& url,
77 const Referrer& referrer,
78 WindowOpenDisposition disposition,
79 ui::PageTransition transition) override;
80 bool OnMessageReceived(const IPC::Message& message,
81 RenderFrameHost* render_frame_host) override;
82 void WebContentsDestroyed() override;
84 private:
85 explicit WebContentsObserverSanityChecker(WebContents* web_contents);
86 ~WebContentsObserverSanityChecker() override;
88 std::string Format(RenderFrameHost* render_frame_host);
89 void AssertRenderFrameExists(RenderFrameHost* render_frame_host);
90 void AssertMainFrameExists();
92 std::set<std::pair<int, int>> current_hosts_;
93 std::set<std::pair<int, int>> live_routes_;
94 std::set<std::pair<int, int>> deleted_routes_;
96 bool web_contents_destroyed_;
98 DISALLOW_COPY_AND_ASSIGN(WebContentsObserverSanityChecker);
101 } // namespace content
103 #endif // CONTENT_TEST_WEB_CONTENTS_OBSERVER_SANITY_CHECKER_H_