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

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 "base/bind.h"
6 #include "content/browser/loader/cross_site_resource_handler.h"
7 #include "content/browser/loader/resource_dispatcher_host_impl.h"
8 #include "content/browser/loader/resource_request_info_impl.h"
9 #include "content/browser/transition_request_manager.h"
10 #include "content/browser/web_contents/web_contents_impl.h"
11 #include "content/public/browser/web_contents_observer.h"
12 #include "content/public/test/content_browser_test.h"
13 #include "content/public/test/content_browser_test_utils.h"
14 #include "content/public/test/test_utils.h"
15 #include "content/shell/browser/shell.h"
16 #include "content/shell/browser/shell_resource_dispatcher_host_delegate.h"
17 #include "net/test/embedded_test_server/embedded_test_server.h"
18 #include "net/url_request/url_request.h"
19
20 namespace content {
21
22 class TransitionBrowserTest : public ContentBrowserTest {
23 public:
24 TransitionBrowserTest() {}
25
26 private:
27 DISALLOW_COPY_AND_ASSIGN(TransitionBrowserTest);
28 };
29
30 class TransitionBrowserTestObserver
31 : public WebContentsObserver,
32 public ShellResourceDispatcherHostDelegate {
33 public:
34 TransitionBrowserTestObserver(Shell* shell)
35 : WebContentsObserver(shell->web_contents()),
36 request_(NULL),
37 shell_(shell),
38 did_defer_response_(false),
39 is_transition_request_(false) {
40 }
41
42 virtual void RequestBeginning(
43 net::URLRequest* request,
44 ResourceContext* resource_context,
45 appcache::AppCacheService* appcache_service,
46 ResourceType::Type resource_type,
47 int child_id,
48 int route_id,
49 ScopedVector<ResourceThrottle>* throttles) OVERRIDE {
50 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
51 ShellResourceDispatcherHostDelegate::RequestBeginning(request,
52 resource_context,
53 appcache_service,
54 resource_type,
55 child_id,
56 route_id,
57 throttles);
58 request_ = request;
59
60 ResourceRequestInfoImpl* info =
61 ResourceRequestInfoImpl::ForRequest(request_);
62
63 TransitionRequestManager::GetInstance()->SetHasPendingTransitionRequest(
64 child_id, info->GetRenderFrameID(), is_transition_request_);
65 }
66
67 virtual void OnResponseStarted(
68 net::URLRequest* request,
69 ResourceContext* resource_context,
70 ResourceResponse* response,
71 IPC::Sender* sender) {
72 ResourceRequestInfoImpl* info =
73 ResourceRequestInfoImpl::ForRequest(request_);
74
75 did_defer_response_ = info->cross_site_handler()->did_defer_for_testing();
76 }
77
78 void set_pending_transition_request(bool is_transition_request) {
79 is_transition_request_ = is_transition_request;
80 }
81
82 bool did_defer_response() const { return did_defer_response_; }
83
84 private:
85 net::URLRequest* request_;
86 Shell* shell_;
87 bool did_defer_response_;
88 bool is_transition_request_;
89 };
90
91 // This tests that normal navigations don't defer at first response.
92 IN_PROC_BROWSER_TEST_F(TransitionBrowserTest,
93 NormalNavigationNotDeferred) {
94 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
95 scoped_ptr<TransitionBrowserTestObserver> observer(
96 new TransitionBrowserTestObserver(shell()));
97
98 ResourceDispatcherHost::Get()->SetDelegate(observer.get());
99
100 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html"));
101
102 ASSERT_FALSE(observer->did_defer_response());
103 }
104
105 // This tests that when a navigation transition is detected, the response is
106 // deferred.
107 IN_PROC_BROWSER_TEST_F(TransitionBrowserTest,
108 TransitionNavigationIsDeferred) {
109 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
110 scoped_ptr<TransitionBrowserTestObserver> observer(
111 new TransitionBrowserTestObserver(shell()));
112
113 ResourceDispatcherHost::Get()->SetDelegate(observer.get());
114 observer->set_pending_transition_request(true);
115
116 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html"));
117
118 ASSERT_TRUE(observer->did_defer_response());
119 }
120
121 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698