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

Side by Side Diff: content/browser/transition_browsertest.cc

Issue 297973002: Navigation transitions: Block first response until after transitions have run. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes from review. Created 6 years, 6 months 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
OLDNEW
(Empty)
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.
4
5 #include "content/browser/loader/cross_site_resource_handler.h"
6 #include "content/browser/loader/resource_dispatcher_host_impl.h"
7 #include "content/browser/loader/resource_request_info_impl.h"
8 #include "content/browser/transition_request_manager.h"
9 #include "content/browser/web_contents/web_contents_impl.h"
10 #include "content/public/browser/web_contents_observer.h"
11 #include "content/public/test/content_browser_test.h"
12 #include "content/public/test/content_browser_test_utils.h"
13 #include "content/public/test/test_utils.h"
14 #include "content/shell/browser/shell.h"
15 #include "content/shell/browser/shell_resource_dispatcher_host_delegate.h"
16 #include "net/test/embedded_test_server/embedded_test_server.h"
17 #include "net/url_request/url_request.h"
18
19 namespace content {
20
21 class TransitionBrowserTest : public ContentBrowserTest {
22 public:
23 TransitionBrowserTest() {}
24
25 private:
26 DISALLOW_COPY_AND_ASSIGN(TransitionBrowserTest);
27 };
28
29 class TransitionBrowserTestObserver
30 : public WebContentsObserver,
31 public ShellResourceDispatcherHostDelegate {
32 public:
33 TransitionBrowserTestObserver(Shell* shell)
34 : WebContentsObserver(shell->web_contents()),
35 request_(NULL),
36 shell_(shell),
37 provisional_load_started_(false),
38 did_defer_response_(false),
39 is_transition_request_(false) {}
40
41 virtual void RequestBeginning(
42 net::URLRequest* request,
43 ResourceContext* resource_context,
44 appcache::AppCacheService* appcache_service,
45 ResourceType::Type resource_type,
46 int child_id,
47 int route_id,
48 ScopedVector<ResourceThrottle>* throttles) OVERRIDE {
49 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
50 ShellResourceDispatcherHostDelegate::RequestBeginning(request,
51 resource_context,
52 appcache_service,
53 resource_type,
54 child_id,
55 route_id,
56 throttles);
57 request_ = request;
58 }
59
60 virtual void DidStartProvisionalLoadForFrame(
61 int64 frame_id,
62 int64 parent_frame_id,
63 bool is_main_frame,
64 const GURL& validated_url,
65 bool is_error_page,
66 bool is_iframe_srcdoc,
67 RenderViewHost* render_view_host) OVERRIDE {
68 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
69 provisional_load_started_ = true;
70 shell_->web_contents()->SetHasPendingTransitionRequest(
71 is_transition_request_);
72 }
73
74 virtual void DidDeferAfterResponseStarted() OVERRIDE {
75 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
76 ASSERT_TRUE(provisional_load_started_);
77 did_defer_response_ = true;
78
79 // Check that the request is currently blocked
80 ResourceRequestInfoImpl* info =
81 ResourceRequestInfoImpl::ForRequest(request_);
82
83 ASSERT_TRUE(info->cross_site_handler()->is_deferred_for_testing());
84
85 shell_->web_contents()->ResumeResponseDeferredAtStart();
86 }
87
88 void set_pending_transition_request(bool is_transition_request) {
89 is_transition_request_ = is_transition_request;
90 }
91
92 bool did_defer_response() const { return did_defer_response_; }
93
94 private:
95 net::URLRequest* request_;
96 Shell* shell_;
97 bool provisional_load_started_;
98 bool did_defer_response_;
99 bool is_transition_request_;
100 };
101
102 // This tests that DidDeferAfterResponseStarted is not called on normal
103 // navigations.
104 IN_PROC_BROWSER_TEST_F(TransitionBrowserTest,
105 DidDeferAfterResponseStartedNotCalled) {
106 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
107 scoped_ptr<TransitionBrowserTestObserver> observer(
108 new TransitionBrowserTestObserver(shell()));
109
110 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html"));
111
112 ASSERT_FALSE(observer->did_defer_response());
113 }
114
115 // This tests that DidDeferAfterResponseStarted is called on a transition
116 // navigation, and that the request is deferred.
117 IN_PROC_BROWSER_TEST_F(TransitionBrowserTest, ShouldDeferAtFirstResponse) {
118 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
119 scoped_ptr<TransitionBrowserTestObserver> observer(
120 new TransitionBrowserTestObserver(shell()));
121
122 ResourceDispatcherHost::Get()->SetDelegate(observer.get());
123 observer->set_pending_transition_request(true);
124
125 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html"));
126
127 ASSERT_TRUE(observer->did_defer_response());
128 }
129
130 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698