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

Side by Side Diff: chrome/browser/garbled_text_browsertest.cc

Issue 9235004: [Garbled Text][Infobar] Adding infobar to suggest turning on encoding detection. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase Created 8 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
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/garbled_text_helper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "base/bind.h"
6 #include "base/message_loop.h"
7 #include "chrome/browser/garbled_text_helper.h"
8 #include "chrome/browser/garbled_text_infobar_delegate.h"
9 #include "chrome/browser/garbled_text_service.h"
10 #include "chrome/browser/garbled_text_url_tracker.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/renderer_host/dummy_resource_dispatcher_host_delegate.h "
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "chrome/test/base/ui_test_utils.h"
17 #include "content/browser/renderer_host/resource_dispatcher_host.h"
18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/common/resource_response.h"
20 #include "content/test/test_browser_thread.h"
21 #include "googleurl/src/gurl.h"
22
23 namespace {
24
25 void Nop() {}
26
27 class TestingRDHDelegate : public DummyResourceDispatcherHostDelegate {
28 public:
29 TestingRDHDelegate(ResourceDispatcherHost* rdh,
30 const GURL& url)
31 : DummyResourceDispatcherHostDelegate(rdh->delegate()),
32 rdh_(rdh),
33 url_(url),
34 completed_(false),
35 needs_encoding_detection_(false) {
36 rdh_->set_delegate(this);
37 }
38
39 virtual ~TestingRDHDelegate() {
40 DCHECK_EQ(this, rdh_->delegate());
41 rdh_->set_delegate(underlying());
42 }
43
44 virtual void OnResponseStarted(
45 net::URLRequest* request,
46 content::ResourceResponse* response,
47 ResourceMessageFilter* filter) OVERRIDE {
48 DummyResourceDispatcherHostDelegate::OnResponseStarted(
49 request, response, filter);
50 if (request->url() == url_) {
51 completed_ = true;
52 needs_encoding_detection_ = response->needs_encoding_detection;
53 }
54 }
55
56 void reset(GURL url) {
57 url_ = url;
58 completed_ = false;
59 needs_encoding_detection_ = false;
60 }
61
62 bool completed() const {
63 return completed_;
64 }
65
66 bool needs_encoding_detection() const {
67 return needs_encoding_detection_;
68 }
69
70 private:
71 ResourceDispatcherHost* rdh_;
72 GURL url_;
73 bool completed_;
74 bool needs_encoding_detection_;
75 };
76
77 } // anonymous namespace
78
79 class GarbledTextBrowserTest : public InProcessBrowserTest {
80 public:
81 typedef GarbledTextURLTracker::GarbledURLs GarbledURLs;
82
83 protected:
84 GarbledTextBrowserTest() {}
85 ~GarbledTextBrowserTest() {}
86
87 void UpdateBlacklist(const GURL& url) {
88 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
89 content::BrowserThread::PostTask(
90 content::BrowserThread::UI,
91 FROM_HERE,
92 base::Bind(&GarbledTextBrowserTest::UpdateBlacklist,
93 base::Unretained(this), url));
94 ui_test_utils::RunAllPendingInMessageLoop(content::BrowserThread::UI);
95 return;
96 }
97
98 GarbledURLs urls(&url, &url+1);
99 GarbledTextService* service = GarbledTextServiceFactory::GetInstance()->
100 GetForProfile(browser()->profile());
101 service->UpdateBlacklist(urls, base::Bind(&Nop));
102 ui_test_utils::RunAllPendingInMessageLoop(content::BrowserThread::IO);
103 }
104
105 private:
106 DISALLOW_COPY_AND_ASSIGN(GarbledTextBrowserTest);
107 };
108
109 IN_PROC_BROWSER_TEST_F(GarbledTextBrowserTest, LoadTimeMarkingTest) {
110 ASSERT_TRUE(test_server()->Start());
111
112 GURL url(test_server()->GetURL("files/garbled_text/foo.html"));
113 TestingRDHDelegate delegate(ResourceDispatcherHost::Get(),
114 url);
115
116 ui_test_utils::NavigateToURL(browser(), url);
117 EXPECT_TRUE(delegate.completed());
118 EXPECT_FALSE(delegate.needs_encoding_detection());
119
120 UpdateBlacklist(url);
121
122 delegate.reset(url);
123 ui_test_utils::NavigateToURL(browser(), url);
124 EXPECT_TRUE(delegate.completed());
125 EXPECT_TRUE(delegate.needs_encoding_detection());
126
127 test_server()->Stop();
128 }
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/garbled_text_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698