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

Side by Side Diff: chrome/browser/autocomplete/shortcuts_provider_extension_unittest.cc

Issue 1654833005: Componentizes shortcuts unittests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 (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 "components/omnibox/browser/shortcuts_provider.h"
6
7 #include <set>
8 #include <string>
9 #include <vector>
10
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/message_loop/message_loop.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h"
16 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
17 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h"
18 #include "chrome/test/base/testing_profile.h"
19 #include "components/history/core/browser/history_service.h"
20 #include "components/omnibox/browser/autocomplete_input.h"
21 #include "components/omnibox/browser/autocomplete_match.h"
22 #include "components/omnibox/browser/autocomplete_result.h"
23 #include "components/omnibox/browser/shortcuts_backend.h"
24 #include "components/omnibox/browser/shortcuts_provider_test_util.h"
25 #include "content/public/browser/notification_service.h"
26 #include "content/public/test/test_browser_thread.h"
27 #include "testing/gtest/include/gtest/gtest.h"
28
29 #if defined(ENABLE_EXTENSIONS)
30 #include "extensions/browser/notification_types.h"
31 #include "extensions/common/extension.h"
32 #include "extensions/common/extension_builder.h"
33 #endif
34
35 using ExpectedURLs = std::vector<ExpectedURLAndAllowedToBeDefault>;
36
37 namespace {
38
39 struct TestShortcutData shortcut_test_db[] = {
40 {"BD85DBA2-8C29-49F9-84AE-48E1E90880F1", "echo echo", "echo echo",
41 "chrome-extension://cedabbhfglmiikkmdgcpjdkocfcmbkee/?q=echo",
42 "Run Echo command: echo", "0,0", "Echo", "0,4", ui::PAGE_TRANSITION_TYPED,
43 AutocompleteMatchType::EXTENSION_APP, "echo", 1, 1},
44 };
45
46 } // namespace
47
48 // ShortcutsProviderExtensionTest ---------------------------------------------
49
50 class ShortcutsProviderExtensionTest : public testing::Test {
51 public:
52 ShortcutsProviderExtensionTest();
53
54 protected:
55 void SetUp() override;
56 void TearDown() override;
57
58 base::MessageLoopForUI message_loop_;
59 content::TestBrowserThread ui_thread_;
60 content::TestBrowserThread file_thread_;
61 TestingProfile profile_;
62 ChromeAutocompleteProviderClient client_;
63 scoped_refptr<ShortcutsBackend> backend_;
64 scoped_refptr<ShortcutsProvider> provider_;
65 };
66
67 ShortcutsProviderExtensionTest::ShortcutsProviderExtensionTest()
68 : ui_thread_(content::BrowserThread::UI, &message_loop_),
69 file_thread_(content::BrowserThread::FILE, &message_loop_),
70 client_(&profile_) {}
71
72 void ShortcutsProviderExtensionTest::SetUp() {
73 ShortcutsBackendFactory::GetInstance()->SetTestingFactoryAndUse(
74 &profile_, &ShortcutsBackendFactory::BuildProfileNoDatabaseForTesting);
75 backend_ = ShortcutsBackendFactory::GetForProfile(&profile_);
76 ASSERT_TRUE(backend_.get());
77 ASSERT_TRUE(profile_.CreateHistoryService(true, false));
78 provider_ = new ShortcutsProvider(&client_);
79 PopulateShortcutsBackendWithTestData(client_.GetShortcutsBackend(),
80 shortcut_test_db,
81 arraysize(shortcut_test_db));
82 }
83
84 void ShortcutsProviderExtensionTest::TearDown() {
85 // Run all pending tasks or else some threads hold on to the message loop
86 // and prevent it from being deleted.
87 message_loop_.RunUntilIdle();
88 profile_.DestroyHistoryService();
89 provider_ = NULL;
90 }
91
92 // Actual tests ---------------------------------------------------------------
93
94 #if defined(ENABLE_EXTENSIONS)
95 TEST_F(ShortcutsProviderExtensionTest, Extension) {
96 // Try an input string that matches an extension URL.
97 base::string16 text(base::ASCIIToUTF16("echo"));
98 std::string expected_url(
99 "chrome-extension://cedabbhfglmiikkmdgcpjdkocfcmbkee/?q=echo");
100 ExpectedURLs expected_urls;
101 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true));
102 RunShortcutsProviderTest(provider_, text, false, expected_urls, expected_url,
103 base::ASCIIToUTF16(" echo"));
104
105 // Claim the extension has been unloaded.
106 scoped_refptr<const extensions::Extension> extension =
107 extensions::ExtensionBuilder()
108 .SetManifest(std::move(extensions::DictionaryBuilder()
109 .Set("name", "Echo")
110 .Set("version", "1.0")))
111 .SetID("cedabbhfglmiikkmdgcpjdkocfcmbkee")
112 .Build();
113 extensions::UnloadedExtensionInfo details(
114 extension.get(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL);
115 content::NotificationService::current()->Notify(
116 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
117 content::Source<Profile>(&profile_),
118 content::Details<extensions::UnloadedExtensionInfo>(&details));
119
120 // Now the URL should have disappeared.
121 RunShortcutsProviderTest(provider_, text, false, ExpectedURLs(),
122 std::string(), base::string16());
123 }
124 #endif
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/shortcuts_backend_unittest.cc ('k') | chrome/browser/autocomplete/shortcuts_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698