Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / components / omnibox / browser / clipboard_url_provider_unittest.cc
blobeea98821600dfa89386c9c50dd12ce3c5da4dd2a
1 // Copyright 2015 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.
5 #include "components/omnibox/browser/clipboard_url_provider.h"
7 #include <string>
9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/omnibox/browser/autocomplete_input.h"
13 #include "components/omnibox/browser/mock_autocomplete_provider_client.h"
14 #include "components/omnibox/browser/test_scheme_classifier.h"
15 #include "components/open_from_clipboard/fake_clipboard_recent_content.h"
16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "url/gurl.h"
20 namespace {
22 const char kCurrentURL[] = "http://example.com/current";
23 const char kClipboardURL[] = "http://example.com/clipboard";
25 class ClipboardURLProviderTest : public testing::Test {
26 public:
27 ClipboardURLProviderTest()
28 : client_(new testing::NiceMock<MockAutocompleteProviderClient>()),
29 provider_(
30 new ClipboardURLProvider(client_.get(), &clipboard_content_)) {
31 SetClipboardUrl(GURL(kClipboardURL));
34 ~ClipboardURLProviderTest() override {}
36 void ClearClipboard() { clipboard_content_.SuppressClipboardContent(); }
38 void SetClipboardUrl(const GURL& url) {
39 clipboard_content_.SetClipboardContent(url,
40 base::TimeDelta::FromMinutes(10));
43 AutocompleteInput CreateAutocompleteInput(bool from_omnibox_focus) {
44 return AutocompleteInput(
45 base::string16(), base::string16::npos, std::string(),
46 GURL(kCurrentURL), metrics::OmniboxEventProto::INVALID_SPEC, false,
47 false, false, false, from_omnibox_focus, classifier_);
50 protected:
51 TestSchemeClassifier classifier_;
52 FakeClipboardRecentContent clipboard_content_;
53 scoped_ptr<testing::NiceMock<MockAutocompleteProviderClient>> client_;
54 scoped_refptr<ClipboardURLProvider> provider_;
57 TEST_F(ClipboardURLProviderTest, NotFromOmniboxFocus) {
58 provider_->Start(CreateAutocompleteInput(false), false);
59 EXPECT_TRUE(provider_->matches().empty());
62 TEST_F(ClipboardURLProviderTest, EmptyClipboard) {
63 ClearClipboard();
64 provider_->Start(CreateAutocompleteInput(true), false);
65 EXPECT_TRUE(provider_->matches().empty());
68 TEST_F(ClipboardURLProviderTest, ClipboardIsCurrentURL) {
69 SetClipboardUrl(GURL(kCurrentURL));
70 provider_->Start(CreateAutocompleteInput(true), false);
71 EXPECT_TRUE(provider_->matches().empty());
74 TEST_F(ClipboardURLProviderTest, HasMultipleMatches) {
75 provider_->Start(CreateAutocompleteInput(true), false);
76 ASSERT_GE(provider_->matches().size(), 1U);
77 EXPECT_EQ(GURL(kClipboardURL), provider_->matches().back().destination_url);
80 } // namespace