Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / search / thumbnail_source_unittest.cc
blob923b4bf190c96003147e76c38c4de4109e7e63fe
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 "chrome/browser/search/thumbnail_source.h"
7 #include "chrome/test/base/testing_browser_process.h"
8 #include "chrome/test/base/testing_profile.h"
9 #include "chrome/test/base/testing_profile_manager.h"
10 #include "content/public/test/test_browser_thread_bundle.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "url/gurl.h"
14 class ThumbnailSourceTest : public testing::Test {
15 protected:
16 ThumbnailSourceTest() {}
17 ~ThumbnailSourceTest() override {}
19 void SetUp() override {
20 profile_manager_.reset(
21 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
22 ASSERT_TRUE(profile_manager_->SetUp());
23 profile_ = profile_manager_->CreateTestingProfile("testing-profile");
26 Profile* profile() { return profile_; }
28 private:
29 content::TestBrowserThreadBundle thread_bundle_;
30 scoped_ptr<TestingProfileManager> profile_manager_;
31 TestingProfile* profile_; // Owned by TestingProfileManager.
34 TEST_F(ThumbnailSourceTest, ExtractPageAndThumbnailUrlsValidCase) {
35 ThumbnailSource thumbnail_source(profile(), false);
37 std::string path = "http://www.abc.com/?fb=http://www.xyz.com/";
39 GURL thumbnail_url_1, thumbnail_url_2;
40 thumbnail_source.ExtractPageAndThumbnailUrls(path, &thumbnail_url_1,
41 &thumbnail_url_2);
43 EXPECT_EQ("http://www.abc.com/", thumbnail_url_1.spec());
44 EXPECT_TRUE(thumbnail_url_1.is_valid());
45 EXPECT_EQ("http://www.xyz.com/", thumbnail_url_2.spec());
46 EXPECT_TRUE(thumbnail_url_2.is_valid());
49 TEST_F(ThumbnailSourceTest, ExtractPageAndThumbnailUrlsNoDelimiter) {
50 ThumbnailSource thumbnail_source(profile(), false);
52 std::string path = "http://www.abc.com/http://www.xyz.com/";
54 GURL thumbnail_url_1, thumbnail_url_2;
55 thumbnail_source.ExtractPageAndThumbnailUrls(path, &thumbnail_url_1,
56 &thumbnail_url_2);
58 EXPECT_EQ(path, thumbnail_url_1.spec());
59 EXPECT_TRUE(thumbnail_url_2.is_empty());
62 TEST_F(ThumbnailSourceTest, ExtractPageAndThumbnailUrlsTwoDelimiters) {
63 ThumbnailSource thumbnail_source(profile(), false);
65 std::string path = "http://www.abc.com/?fb=?fb=http://www.xyz.com/";
67 GURL thumbnail_url_1, thumbnail_url_2;
68 thumbnail_source.ExtractPageAndThumbnailUrls(path, &thumbnail_url_1,
69 &thumbnail_url_2);
71 EXPECT_EQ("http://www.abc.com/", thumbnail_url_1.spec());
72 EXPECT_TRUE(thumbnail_url_1.is_valid());
73 EXPECT_FALSE(thumbnail_url_2.is_valid());
76 TEST_F(ThumbnailSourceTest, ExtractPageAndThumbnailUrlsInvalidFirstUrl) {
77 ThumbnailSource thumbnail_source(profile(), false);
79 std::string path = "http://!@#$%^&*()_+/?fb=http://www.xyz.com/";
81 GURL thumbnail_url_1, thumbnail_url_2;
82 thumbnail_source.ExtractPageAndThumbnailUrls(path, &thumbnail_url_1,
83 &thumbnail_url_2);
85 EXPECT_FALSE(thumbnail_url_1.is_valid());
86 EXPECT_EQ("http://www.xyz.com/", thumbnail_url_2.spec());
87 EXPECT_TRUE(thumbnail_url_2.is_valid());
90 TEST_F(ThumbnailSourceTest, ExtractPageAndThumbnailUrlsInvalidSecondUrl) {
91 ThumbnailSource thumbnail_source(profile(), false);
93 std::string path = "http://www.abc.com/?fb=http://!@#$%^&*()_+/";
95 GURL thumbnail_url_1, thumbnail_url_2;
96 thumbnail_source.ExtractPageAndThumbnailUrls(path, &thumbnail_url_1,
97 &thumbnail_url_2);
99 EXPECT_EQ("http://www.abc.com/", thumbnail_url_1.spec());
100 EXPECT_TRUE(thumbnail_url_1.is_valid());
101 EXPECT_FALSE(thumbnail_url_2.is_valid());