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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/autocomplete/autocomplete_match.h" | 8 #include "chrome/browser/autocomplete/autocomplete_match.h" |
9 #include "chrome/browser/autocomplete/extension_app_provider.h" | 9 #include "chrome/browser/autocomplete/extension_app_provider.h" |
10 #include "chrome/browser/history/history_service.h" | 10 #include "chrome/browser/history/history_service.h" |
11 #include "chrome/browser/history/history_service_factory.h" | 11 #include "chrome/browser/history/history_service_factory.h" |
12 #include "chrome/browser/history/url_database.h" | 12 #include "chrome/browser/history/url_database.h" |
13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
14 #include "content/public/test/test_browser_thread.h" | 14 #include "content/public/test/test_browser_thread.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 using base::ASCIIToUTF16; | 17 using base::ASCIIToUTF16; |
18 | 18 |
19 class ExtensionAppProviderTest : public testing::Test { | 19 class ExtensionAppProviderTest : public testing::Test { |
20 protected: | 20 protected: |
21 struct test_data { | 21 struct test_data { |
22 const base::string16 input; | 22 const base::string16 input; |
23 const size_t num_results; | 23 const size_t num_results; |
24 const GURL output[3]; | 24 const GURL output[3]; |
25 }; | 25 }; |
26 | 26 |
27 ExtensionAppProviderTest() | 27 ExtensionAppProviderTest() |
28 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 28 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
29 profile_(new TestingProfile), | 29 history_service_(NULL) { } |
30 app_provider_(new ExtensionAppProvider(NULL, profile_.get())), | |
31 history_service_(NULL) {} | |
32 virtual ~ExtensionAppProviderTest() { } | 30 virtual ~ExtensionAppProviderTest() { } |
33 | 31 |
34 virtual void SetUp() OVERRIDE; | 32 virtual void SetUp() OVERRIDE; |
35 | 33 |
36 void RunTest(test_data* keyword_cases, | 34 void RunTest(test_data* keyword_cases, |
37 int num_cases); | 35 int num_cases); |
38 | 36 |
39 protected: | 37 protected: |
40 base::MessageLoopForUI message_loop_; | 38 base::MessageLoopForUI message_loop_; |
41 content::TestBrowserThread ui_thread_; | 39 content::TestBrowserThread ui_thread_; |
| 40 scoped_refptr<ExtensionAppProvider> app_provider_; |
42 scoped_ptr<TestingProfile> profile_; | 41 scoped_ptr<TestingProfile> profile_; |
43 scoped_refptr<ExtensionAppProvider> app_provider_; | |
44 HistoryService* history_service_; | 42 HistoryService* history_service_; |
45 }; | 43 }; |
46 | 44 |
47 void ExtensionAppProviderTest::SetUp() { | 45 void ExtensionAppProviderTest::SetUp() { |
| 46 profile_.reset(new TestingProfile()); |
48 ASSERT_TRUE(profile_->CreateHistoryService(true, false)); | 47 ASSERT_TRUE(profile_->CreateHistoryService(true, false)); |
49 profile_->BlockUntilHistoryProcessesPendingRequests(); | 48 profile_->BlockUntilHistoryProcessesPendingRequests(); |
50 history_service_ = | 49 history_service_ = |
51 HistoryServiceFactory::GetForProfile(profile_.get(), | 50 HistoryServiceFactory::GetForProfile(profile_.get(), |
52 Profile::EXPLICIT_ACCESS); | 51 Profile::EXPLICIT_ACCESS); |
53 | 52 |
| 53 app_provider_ = new ExtensionAppProvider(NULL, profile_.get()); |
| 54 |
54 struct TestExtensionApp { | 55 struct TestExtensionApp { |
55 const char* app_name; | 56 const char* app_name; |
56 const char* launch_url; | 57 const char* launch_url; |
57 bool should_match_against_launch_url; | 58 bool should_match_against_launch_url; |
58 const char* title; | 59 const char* title; |
59 int typed_count; | 60 int typed_count; |
60 } kExtensionApps[] = { | 61 } kExtensionApps[] = { |
61 {"COYB", "http://asdf/", true, "COYB", 7}, | 62 {"COYB", "http://asdf/", true, "COYB", 7}, |
62 {"NSNO", "http://fdsa/", true, "NSNO", 2}, | 63 {"NSNO", "http://fdsa/", true, "NSNO", 2}, |
63 {"APPP", "chrome-extension://xyz/", false, "APPP", 2}, | 64 {"APPP", "chrome-extension://xyz/", false, "APPP", 2}, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 ExtensionAppProvider::ExtensionApp extension_app = | 148 ExtensionAppProvider::ExtensionApp extension_app = |
148 {ASCIIToUTF16(cases[i].name), url, true}; | 149 {ASCIIToUTF16(cases[i].name), url, true}; |
149 AutocompleteMatch match = | 150 AutocompleteMatch match = |
150 app_provider_->CreateAutocompleteMatch(input, | 151 app_provider_->CreateAutocompleteMatch(input, |
151 extension_app, | 152 extension_app, |
152 0, | 153 0, |
153 base::string16::npos); | 154 base::string16::npos); |
154 EXPECT_EQ(ASCIIToUTF16(cases[i].match_contents), match.contents); | 155 EXPECT_EQ(ASCIIToUTF16(cases[i].match_contents), match.contents); |
155 } | 156 } |
156 } | 157 } |
OLD | NEW |