OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/string16.h" | 5 #include "base/string16.h" |
6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/ui/find_bar/find_bar_state.h" | 8 #include "chrome/browser/ui/find_bar/find_bar_state.h" |
9 #include "chrome/browser/ui/find_bar/find_bar_state_factory.h" | 9 #include "chrome/browser/ui/find_bar/find_bar_state_factory.h" |
10 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | 10 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
12 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" | 12 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" |
13 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
14 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
15 #include "content/browser/tab_contents/test_tab_contents.h" | 15 #include "content/public/browser/web_contents.h" |
16 #include "content/test/test_browser_thread.h" | 16 #include "content/test/test_browser_thread.h" |
| 17 #include "content/test/web_contents_tester.h" |
17 | 18 |
18 using content::BrowserThread; | 19 using content::BrowserThread; |
| 20 using content::WebContents; |
| 21 using content::WebContentsTester; |
19 | 22 |
20 class FindBackendTest : public TabContentsWrapperTestHarness { | 23 class FindBackendTest : public TabContentsWrapperTestHarness { |
21 public: | 24 public: |
22 FindBackendTest() | 25 FindBackendTest() |
23 : TabContentsWrapperTestHarness(), | 26 : TabContentsWrapperTestHarness(), |
24 browser_thread_(BrowserThread::UI, &message_loop_) {} | 27 browser_thread_(BrowserThread::UI, &message_loop_) {} |
25 | 28 |
26 private: | 29 private: |
27 content::TestBrowserThread browser_thread_; | 30 content::TestBrowserThread browser_thread_; |
28 }; | 31 }; |
29 | 32 |
30 namespace { | 33 namespace { |
31 | 34 |
32 string16 FindPrepopulateText(TabContents* contents) { | 35 string16 FindPrepopulateText(WebContents* contents) { |
33 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 36 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
34 return FindBarStateFactory::GetLastPrepopulateText(profile); | 37 return FindBarStateFactory::GetLastPrepopulateText(profile); |
35 } | 38 } |
36 | 39 |
37 } // end namespace | 40 } // end namespace |
38 | 41 |
39 // This test takes two TabContents objects, searches in both of them and | 42 // This test takes two TabContents objects, searches in both of them and |
40 // tests the internal state for find_text and find_prepopulate_text. | 43 // tests the internal state for find_text and find_prepopulate_text. |
41 TEST_F(FindBackendTest, InternalState) { | 44 TEST_F(FindBackendTest, InternalState) { |
42 FindTabHelper* find_tab_helper = contents_wrapper()->find_tab_helper(); | 45 FindTabHelper* find_tab_helper = contents_wrapper()->find_tab_helper(); |
43 // Initial state for the TabContents is blank strings. | 46 // Initial state for the TabContents is blank strings. |
44 EXPECT_EQ(string16(), FindPrepopulateText(contents())); | 47 EXPECT_EQ(string16(), FindPrepopulateText(contents())); |
45 EXPECT_EQ(string16(), find_tab_helper->find_text()); | 48 EXPECT_EQ(string16(), find_tab_helper->find_text()); |
46 | 49 |
47 // Get another TabContents object ready. | 50 // Get another TabContents object ready. |
48 TestTabContents* contents2 = new TestTabContents(profile(), NULL); | 51 WebContents* contents2 = |
| 52 WebContentsTester::CreateTestWebContents(profile(), NULL); |
49 TabContentsWrapper wrapper2(contents2); | 53 TabContentsWrapper wrapper2(contents2); |
50 FindTabHelper* find_tab_helper2 = wrapper2.find_tab_helper(); | 54 FindTabHelper* find_tab_helper2 = wrapper2.find_tab_helper(); |
51 | 55 |
52 // No search has still been issued, strings should be blank. | 56 // No search has still been issued, strings should be blank. |
53 EXPECT_EQ(string16(), FindPrepopulateText(contents())); | 57 EXPECT_EQ(string16(), FindPrepopulateText(contents())); |
54 EXPECT_EQ(string16(), find_tab_helper->find_text()); | 58 EXPECT_EQ(string16(), find_tab_helper->find_text()); |
55 EXPECT_EQ(string16(), FindPrepopulateText(contents2)); | 59 EXPECT_EQ(string16(), FindPrepopulateText(contents2)); |
56 EXPECT_EQ(string16(), find_tab_helper2->find_text()); | 60 EXPECT_EQ(string16(), find_tab_helper2->find_text()); |
57 | 61 |
58 string16 search_term1 = ASCIIToUTF16(" I had a 401K "); | 62 string16 search_term1 = ASCIIToUTF16(" I had a 401K "); |
(...skipping 26 matching lines...) Expand all Loading... |
85 // find_tab_helper (as indicated by the last two params). | 89 // find_tab_helper (as indicated by the last two params). |
86 find_tab_helper->StartFinding(search_term3, true, false); | 90 find_tab_helper->StartFinding(search_term3, true, false); |
87 | 91 |
88 // Once more, pre-populate string should always match between the two, but | 92 // Once more, pre-populate string should always match between the two, but |
89 // find_text should not. | 93 // find_text should not. |
90 EXPECT_EQ(search_term3, FindPrepopulateText(contents())); | 94 EXPECT_EQ(search_term3, FindPrepopulateText(contents())); |
91 EXPECT_EQ(search_term3, find_tab_helper->find_text()); | 95 EXPECT_EQ(search_term3, find_tab_helper->find_text()); |
92 EXPECT_EQ(search_term3, FindPrepopulateText(contents2)); | 96 EXPECT_EQ(search_term3, FindPrepopulateText(contents2)); |
93 EXPECT_EQ(search_term2, find_tab_helper2->find_text()); | 97 EXPECT_EQ(search_term2, find_tab_helper2->find_text()); |
94 } | 98 } |
OLD | NEW |