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

Side by Side Diff: chrome/browser/garbled_text_helper_unittest.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/browser/garbled_text_helper.cc ('k') | chrome/browser/garbled_text_infobar_delegate.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 "chrome/browser/garbled_text_helper.h"
6 #include "chrome/browser/garbled_text_infobar_delegate.h"
7 #include "chrome/browser/garbled_text_test_helper.h"
8 #include "chrome/browser/garbled_text_url_tracker.h"
9 #include "chrome/browser/infobars/infobar_tab_helper.h"
10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
11 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h"
12 #include "chrome/test/base/testing_profile.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/test/test_browser_thread.h"
15 #include "googleurl/src/gurl.h"
16
17 class GarbledTextHelperTest : public TabContentsWrapperTestHarness {
18 public:
19 typedef GarbledTextURLTracker::GarbledURLs GarbledURLs;
20 typedef GarbledTextURLTracker::Blacklist Blacklist;
21
22 virtual void SetUp() OVERRIDE {
23 TabContentsWrapperTestHarness::SetUp();
24 test_helper_.reset(new GarbledTextTestHelper(
25 contents_wrapper()->profile()));
26 }
27
28 virtual void TearDown() OVERRIDE {
29 test_helper_.reset();
30 TabContentsWrapperTestHarness::TearDown();
31 }
32
33 protected:
34 GarbledTextHelperTest()
35 : ui_thread_(content::BrowserThread::UI, &message_loop_),
36 io_thread_(content::BrowserThread::IO, &message_loop_) {
37 }
38
39 GarbledTextTestHelper* test_helper() {
40 return test_helper_.get();
41 }
42
43 virtual ~GarbledTextHelperTest() {}
44
45 void OnGarbledTextDetected(const GarbledURLs& garbled_urls) {
46 contents_wrapper()->garbled_text_helper()->OnGarbledTextDetected(
47 garbled_urls);
48 MessageLoop::current()->RunAllPending();
49 }
50
51 GarbledTextInfoBarDelegate* garbled_text_infobar() {
52 InfoBarTabHelper* infobar_helper = contents_wrapper()->infobar_tab_helper();
53 for (size_t i = 0; i < infobar_helper->infobar_count(); ++i) {
54 GarbledTextInfoBarDelegate* result = infobar_helper->
55 GetInfoBarDelegateAt(i)->AsGarbledTextInfoBarDelegate();
56 if (result)
57 return result;
58 }
59 return NULL;
60 }
61
62 void AcceptInfoBar(GarbledTextInfoBarDelegate* infobar) {
63 infobar->Accept();
64 MessageLoop::current()->RunAllPending();
65 }
66
67 const Blacklist& blacklist() {
68 return test_helper()->tracker()->blacklist_;
69 }
70
71 private:
72 content::TestBrowserThread ui_thread_;
73 content::TestBrowserThread io_thread_;
74 scoped_ptr<GarbledTextTestHelper> test_helper_;
75
76 DISALLOW_COPY_AND_ASSIGN(GarbledTextHelperTest);
77 };
78
79 TEST_F(GarbledTextHelperTest, GarbledTextHandlingTest) {
80 test_helper()->Initialize();
81
82 GarbledURLs garbled_urls;
83 garbled_urls.push_back(GURL("http://foo.example.com/"));
84 OnGarbledTextDetected(garbled_urls);
85
86 GarbledTextInfoBarDelegate* infobar = garbled_text_infobar();
87 EXPECT_TRUE(infobar);
88 AcceptInfoBar(infobar);
89
90 EXPECT_EQ(1u, blacklist().size());
91 EXPECT_EQ("foo.example.com", *blacklist().begin());
92 }
OLDNEW
« no previous file with comments | « chrome/browser/garbled_text_helper.cc ('k') | chrome/browser/garbled_text_infobar_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698