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

Side by Side Diff: components/data_reduction_proxy/content/browser/content_lofi_ui_service_unittest.cc

Issue 1558553002: Lo-Fi snackbar should only be shown for the first q=low response of a page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tbansal comments Created 4 years, 11 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 2015 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 "components/data_reduction_proxy/content/browser/content_lofi_ui_servic e.h"
6
7 #include <stddef.h>
8
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/render_frame_host.h"
17 #include "content/public/browser/render_process_host.h"
18 #include "content/public/browser/resource_request_info.h"
19 #include "content/public/browser/web_contents.h"
20 #include "content/public/test/test_renderer_host.h"
21 #include "net/socket/socket_test_util.h"
22 #include "net/url_request/url_request.h"
23 #include "net/url_request/url_request_test_util.h"
24 #include "testing/gtest/include/gtest/gtest.h"
25
26 namespace data_reduction_proxy {
27
28 class ContentLoFiUIServiceTest : public content::RenderViewHostTestHarness {
29 public:
30 ContentLoFiUIServiceTest() : callback_called_(false) {
31 // Cannot use IO_MAIN_LOOP with RenderViewHostTestHarness.
32 SetThreadBundleOptions(content::TestBrowserThreadBundle::REAL_IO_THREAD);
33 }
34
35 void RunTestOnIOThread(base::RunLoop* ui_run_loop) {
36 ASSERT_TRUE(ui_run_loop);
37 EXPECT_TRUE(
38 content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
39
40 net::TestURLRequestContext context(true);
41 net::MockClientSocketFactory mock_socket_factory;
42 net::TestDelegate delegate;
43 context.set_client_socket_factory(&mock_socket_factory);
44 context.Init();
45
46 content_lofi_ui_service_.reset(new ContentLoFiUIService(
47 content::BrowserThread::GetMessageLoopProxyForThread(
48 content::BrowserThread::UI),
49 base::Bind(
50 &ContentLoFiUIServiceTest::NotifyLoFiResponseReceivedCallback,
51 base::Unretained(this))));
52
53 scoped_ptr<net::URLRequest> request = CreateRequest(context, &delegate);
54
55 content_lofi_ui_service_->NotifyLoFiReponseReceived(*request);
56
57 content::BrowserThread::PostTask(
58 content::BrowserThread::UI, FROM_HERE,
59 base::Bind(&base::RunLoop::Quit, base::Unretained(ui_run_loop)));
60 }
61
62 scoped_ptr<net::URLRequest> CreateRequest(
63 const net::TestURLRequestContext& context,
64 net::TestDelegate* delegate) {
65 EXPECT_TRUE(
66 content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
67
68 scoped_ptr<net::URLRequest> request = context.CreateRequest(
69 GURL("http://www.google.com/"), net::IDLE, delegate);
70
71 content::ResourceRequestInfo::AllocateForTesting(
72 request.get(), content::RESOURCE_TYPE_SUB_FRAME, NULL,
73 web_contents()->GetMainFrame()->GetProcess()->GetID(), -1,
74 web_contents()->GetMainFrame()->GetRoutingID(),
75 false, // is_main_frame
76 false, // parent_is_main_frame
77 false, // allow_download
78 false, // is_async
79 true); // is_using_lofi
80
81 return request;
82 }
83
84 void NotifyLoFiResponseReceivedCallback(content::WebContents* web_contents) {
85 EXPECT_TRUE(
86 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
87 callback_called_ = true;
88 }
89
90 void VerifyNotifyLoFiResponseReceivedCallback() {
91 EXPECT_TRUE(
92 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
93 EXPECT_TRUE(callback_called_);
94 }
95
96 private:
97 scoped_ptr<ContentLoFiUIService> content_lofi_ui_service_;
98 bool callback_called_;
99 };
100
101 TEST_F(ContentLoFiUIServiceTest, NotifyLoFiResponseReceived) {
102 base::RunLoop ui_run_loop;
103 content::BrowserThread::PostTask(
104 content::BrowserThread::IO, FROM_HERE,
105 base::Bind(&ContentLoFiUIServiceTest::RunTestOnIOThread,
106 base::Unretained(this), &ui_run_loop));
107 ui_run_loop.Run();
108 base::MessageLoop::current()->RunUntilIdle();
109 VerifyNotifyLoFiResponseReceivedCallback();
110 }
111
112 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698