15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/toolbar/toolbar_model.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h" 8a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/metrics/field_trial.h" 9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/search/search.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/search_engines/template_url_service_factory.h" 13f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "chrome/browser/search_engines/ui_thread_search_terms_data.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/tabs/tab_strip_model.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/toolbar/toolbar_model.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_switches.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/browser_with_test_window_test.h" 1946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "components/google/core/browser/google_switches.h" 20a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "components/variations/entropy_provider.h" 21c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "content/public/browser/navigation_entry.h" 22c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "content/public/common/ssl_status.h" 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/url_constants.h" 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Test data ------------------------------------------------------------------ 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct TestItem { 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL url; 32a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // The expected text to display when both forms of URL replacement are 33a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // inactive. 34a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 expected_text_url_replacement_inactive; 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The expected text to display when query extraction is active. 36a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 expected_text_query_extraction; 37a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // The expected text to display when both query extraction and URL removal are 38a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // active. 39a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 expected_text_both; 40d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) bool would_perform_search_term_replacement; 41d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) bool should_display_url; 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} test_items[] = { 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL("view-source:http://www.google.com"), 45cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("view-source:www.google.com"), 46cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("view-source:www.google.com"), 47a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16(), 487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) false, 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) true 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }, 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL("view-source:chrome://newtab/"), 53cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("view-source:chrome://newtab"), 54cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("view-source:chrome://newtab"), 55a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16(), 567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) false, 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) true 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }, 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL("chrome-extension://monkey/balls.html"), 61cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("chrome-extension://monkey/balls.html"), 62cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("chrome-extension://monkey/balls.html"), 63a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16(), 647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) false, 65c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) true 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }, 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 68f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) GURL(url::kAboutBlankURL), 69f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) base::ASCIIToUTF16(url::kAboutBlankURL), 70f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) base::ASCIIToUTF16(url::kAboutBlankURL), 71a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16(), 727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) false, 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) true 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }, 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL("http://searchurl/?q=tractor+supply"), 77cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("searchurl/?q=tractor+supply"), 78cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("searchurl/?q=tractor+supply"), 79a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16(), 807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) false, 817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) true 827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) }, 837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) { 847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) GURL("http://google.com/search?q=tractor+supply&espv=1"), 85cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("google.com/search?q=tractor+supply&espv=1"), 86cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("google.com/search?q=tractor+supply&espv=1"), 87a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16(), 887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) false, 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) true 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }, 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL("https://google.ca/search?q=tractor+supply"), 93cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("https://google.ca/search?q=tractor+supply"), 94cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("https://google.ca/search?q=tractor+supply"), 95a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16(), 967d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) false, 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) true 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }, 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL("https://google.com/search?q=tractor+supply"), 101cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("https://google.com/search?q=tractor+supply"), 102cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("https://google.com/search?q=tractor+supply"), 103a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16(), 1047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) false, 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) true 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) }, 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GURL("https://google.com/search?q=tractor+supply&espv=1"), 109cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("https://google.com/search?q=tractor+supply&espv=1"), 110cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("tractor supply"), 111cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("tractor supply"), 1127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) true, 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) true 1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) }, 1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GURL("https://google.com/search?q=tractorsupply.com&espv=1"), 117cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("https://google.com/search?q=tractorsupply.com&espv=1"), 118cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("tractorsupply.com"), 119cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("tractorsupply.com"), 1207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) true, 1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) true 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) }, 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GURL("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), 125cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16( 126cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) "https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), 127cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("ftp://tractorsupply.ie"), 128cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("ftp://tractorsupply.ie"), 1297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) true, 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) true 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) }, 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} // namespace 1357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// ToolbarModelTest ----------------------------------------------------------- 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ToolbarModelTest : public BrowserWithTestWindowTest { 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 1417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ToolbarModelTest(); 1425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ToolbarModelTest(Browser::Type browser_type, 1435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) chrome::HostDesktopType host_desktop_type, 1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool hosted_app); 1457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) virtual ~ToolbarModelTest(); 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // BrowserWithTestWindowTest: 1487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) virtual void SetUp() OVERRIDE; 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 151cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) void EnableOriginChipFieldTrial(); 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NavigateAndCheckText(const GURL& url, 153a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16& expected_text, 154d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) bool would_perform_search_term_replacement, 155d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) bool should_display_url); 1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 158a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) scoped_ptr<base::FieldTrialList> field_trial_list_; 1597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(ToolbarModelTest); 1617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}; 162c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)ToolbarModelTest::ToolbarModelTest() { 1647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)ToolbarModelTest::ToolbarModelTest( 1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Browser::Type browser_type, 1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) chrome::HostDesktopType host_desktop_type, 1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool hosted_app) 1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : BrowserWithTestWindowTest(browser_type, 1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) host_desktop_type, 1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) hosted_app) { 1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)ToolbarModelTest::~ToolbarModelTest() { 1767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void ToolbarModelTest::SetUp() { 1797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) BrowserWithTestWindowTest::SetUp(); 1807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( 1817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) profile(), &TemplateURLServiceFactory::BuildInstanceFor); 1827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( 1837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) profile(), &AutocompleteClassifierFactory::BuildInstanceFor); 184eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch UIThreadSearchTermsData::SetGoogleBaseURL("http://google.com/"); 1857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 1867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 187a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void ToolbarModelTest::EnableOriginChipFieldTrial() { 188a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) field_trial_list_.reset(new base::FieldTrialList( 189a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) new metrics::SHA1EntropyProvider("platypus"))); 190cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", 191cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) "Group1 espv:2 origin_chip:1"); 1927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 1937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 194a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void ToolbarModelTest::NavigateAndCheckText( 195d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const GURL& url, 196a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16& expected_text, 197d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) bool would_perform_search_term_replacement, 198d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) bool should_display_url) { 1997d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Check while loading. 2007d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) content::NavigationController* controller = 2017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); 2021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci controller->LoadURL(url, content::Referrer(), ui::PAGE_TRANSITION_LINK, 2037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string()); 2047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ToolbarModel* toolbar_model = browser()->toolbar_model(); 205a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(expected_text, toolbar_model->GetText()); 206d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) EXPECT_EQ(would_perform_search_term_replacement, 207d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) toolbar_model->WouldPerformSearchTermReplacement(false)); 208a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(should_display_url, toolbar_model->ShouldDisplayURL()); 2097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 2107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Check after commit. 2117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) CommitPendingLoad(controller); 2127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Fake a secure connection for HTTPS URLs, or the toolbar will refuse to 2137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // extract search terms. 2147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (url.SchemeIsSecure()) { 2157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller->GetVisibleEntry()->GetSSL().security_style = 216c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) content::SECURITY_STYLE_AUTHENTICATED; 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 218a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(expected_text, toolbar_model->GetText()); 219d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) EXPECT_EQ(would_perform_search_term_replacement, 220d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) toolbar_model->WouldPerformSearchTermReplacement(false)); 221a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(should_display_url, toolbar_model->ShouldDisplayURL()); 222ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 223ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // Now pretend the user started modifying the omnibox. 2243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) toolbar_model->set_input_in_progress(true); 225d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false)); 226d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) EXPECT_EQ(would_perform_search_term_replacement, 227d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) toolbar_model->WouldPerformSearchTermReplacement(true)); 228ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 229ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // Tell the ToolbarModel that the user has stopped editing. This prevents 230ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // this function from having side effects. 2313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) toolbar_model->set_input_in_progress(false); 2327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 2337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 2345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class PopupToolbarModelTest : public ToolbarModelTest { 2355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public: 2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PopupToolbarModelTest(); 2375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual ~PopupToolbarModelTest(); 2385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(PopupToolbarModelTest); 2405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}; 2415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)PopupToolbarModelTest::PopupToolbarModelTest() 2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : ToolbarModelTest(Browser::TYPE_POPUP, 2445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) chrome::HOST_DESKTOP_TYPE_NATIVE, 2455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) false) { 2465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)PopupToolbarModelTest::~PopupToolbarModelTest() { 2495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 2517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Actual tests --------------------------------------------------------------- 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 253a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Test that we only replace URLs when query extraction and URL replacement 254a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// are enabled. 255a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)TEST_F(ToolbarModelTest, ShouldDisplayURL_QueryExtraction) { 256f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) AddTab(browser(), GURL(url::kAboutBlankURL)); 257a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 258d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Before we enable instant extended, query extraction is disabled. 259d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) EXPECT_FALSE(chrome::IsQueryExtractionEnabled()) 2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) << "This test expects query extraction to be disabled."; 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (size_t i = 0; i < arraysize(test_items); ++i) { 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const TestItem& test_item = test_items[i]; 263a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) NavigateAndCheckText(test_item.url, 264a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) test_item.expected_text_url_replacement_inactive, 265a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) false, test_item.should_display_url); 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 268f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) chrome::EnableQueryExtractionForTesting(); 269d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) EXPECT_TRUE(chrome::IsQueryExtractionEnabled()); 270a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled()); 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (size_t i = 0; i < arraysize(test_items); ++i) { 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const TestItem& test_item = test_items[i]; 273a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) NavigateAndCheckText(test_item.url, 274a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) test_item.expected_text_query_extraction, 275d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) test_item.would_perform_search_term_replacement, 276d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) test_item.should_display_url); 277d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) } 278d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 279a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Disabling URL replacement should reset to only showing URLs. 280a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) browser()->toolbar_model()->set_url_replacement_enabled(false); 281a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) for (size_t i = 0; i < arraysize(test_items); ++i) { 282a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const TestItem& test_item = test_items[i]; 283a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) NavigateAndCheckText(test_item.url, 284a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) test_item.expected_text_url_replacement_inactive, 285a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) false, test_item.should_display_url); 286a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 287a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 288a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 289a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Test that we remove or replace URLs appropriately when the origin chip is 290a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// enabled. 291a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)TEST_F(ToolbarModelTest, ShouldDisplayURL_OriginChip) { 292a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EnableOriginChipFieldTrial(); 293f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) AddTab(browser(), GURL(url::kAboutBlankURL)); 294a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 295a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Check each case with the origin chip enabled but query extraction disabled. 296a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(chrome::ShouldDisplayOriginChip()); 297a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(chrome::IsQueryExtractionEnabled()); 298a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) for (size_t i = 0; i < arraysize(test_items); ++i) { 299a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const TestItem& test_item = test_items[i]; 300cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) NavigateAndCheckText(test_item.url, base::string16(), false, 301cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) test_item.should_display_url); 302a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 303a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 304a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Check with both enabled. 305a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) chrome::EnableQueryExtractionForTesting(); 306a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(chrome::IsQueryExtractionEnabled()); 307a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled()); 308d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) for (size_t i = 0; i < arraysize(test_items); ++i) { 309d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const TestItem& test_item = test_items[i]; 310a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) NavigateAndCheckText(test_item.url, test_item.expected_text_both, 311a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) test_item.would_perform_search_term_replacement, 312d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) test_item.should_display_url); 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 314a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 315a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Disabling URL replacement should reset to only showing URLs. 316a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) browser()->toolbar_model()->set_url_replacement_enabled(false); 317a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) for (size_t i = 0; i < arraysize(test_items); ++i) { 318a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const TestItem& test_item = test_items[i]; 319a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) NavigateAndCheckText(test_item.url, 320a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) test_item.expected_text_url_replacement_inactive, 321a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) false, test_item.should_display_url); 322a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 325cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Verify that search terms are extracted while the page is loading. 3267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(ToolbarModelTest, SearchTermsWhileLoading) { 327f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) chrome::EnableQueryExtractionForTesting(); 328f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) AddTab(browser(), GURL(url::kAboutBlankURL)); 329c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 3307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // While loading, we should be willing to extract search terms. 3317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) content::NavigationController* controller = 3327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); 3337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller->LoadURL(GURL("https://google.com/search?q=tractor+supply&espv=1"), 3341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci content::Referrer(), ui::PAGE_TRANSITION_LINK, 3357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string()); 336c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ToolbarModel* toolbar_model = browser()->toolbar_model(); 3377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller->GetVisibleEntry()->GetSSL().security_style = 338c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) content::SECURITY_STYLE_UNKNOWN; 339d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) EXPECT_TRUE(toolbar_model->WouldPerformSearchTermReplacement(false)); 340c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 3417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // When done loading, we shouldn't extract search terms if we didn't get an 3427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // authenticated connection. 3437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) CommitPendingLoad(controller); 3447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) controller->GetVisibleEntry()->GetSSL().security_style = 345c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) content::SECURITY_STYLE_UNKNOWN; 346d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false)); 3472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 348eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 349eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// When the Google base URL is overridden on the command line, we should extract 350eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// search terms from URLs that start with that base URL even when they're not 351eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// secure. 352eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(ToolbarModelTest, GoogleBaseURL) { 353f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) chrome::EnableQueryExtractionForTesting(); 354f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) AddTab(browser(), GURL(url::kAboutBlankURL)); 355eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 356eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // If the Google base URL wasn't specified on the command line, then if it's 357eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // HTTP, we should not extract search terms. 358eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/"); 359eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch NavigateAndCheckText( 360eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), 361cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("www.foo.com/search?q=tractor+supply&espv=1"), false, 362cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) true); 363eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 364eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // The same URL, when specified on the command line, should allow search term 365eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // extraction. 366eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch UIThreadSearchTermsData::SetGoogleBaseURL(std::string()); 367eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, 368eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch "http://www.foo.com/"); 369eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch NavigateAndCheckText( 370eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), 371cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ASCIIToUTF16("tractor supply"), true, true); 372eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 3735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Popup windows don't have an origin chip, so test that URL display in a popup 3755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// ignores whether the origin chip is enabled and only respects the query 3765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// extraction flag. 3775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(PopupToolbarModelTest, ShouldDisplayURL) { 378f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) AddTab(browser(), GURL(url::kAboutBlankURL)); 3795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Check with neither query extraction nor the origin chip enabled. 3815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_FALSE(chrome::ShouldDisplayOriginChip()); 3825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_FALSE(chrome::IsQueryExtractionEnabled()); 3835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) for (size_t i = 0; i < arraysize(test_items); ++i) { 3845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const TestItem& test_item = test_items[i]; 3855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NavigateAndCheckText(test_item.url, 3865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_item.expected_text_url_replacement_inactive, 3875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) false, test_item.should_display_url); 3885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 3895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Check with the origin chip enabled. 3915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EnableOriginChipFieldTrial(); 3925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(chrome::ShouldDisplayOriginChip()); 3935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_FALSE(chrome::IsQueryExtractionEnabled()); 3945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) for (size_t i = 0; i < arraysize(test_items); ++i) { 3955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const TestItem& test_item = test_items[i]; 3965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NavigateAndCheckText(test_item.url, 3975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_item.expected_text_url_replacement_inactive, 3985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) false, test_item.should_display_url); 3995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // With both origin chip and query extraction enabled, only search term 4025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // replacement should be performed. 4035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) chrome::EnableQueryExtractionForTesting(); 4045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(chrome::IsQueryExtractionEnabled()); 4055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled()); 4065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) for (size_t i = 0; i < arraysize(test_items); ++i) { 4075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const TestItem& test_item = test_items[i]; 4085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NavigateAndCheckText(test_item.url, 4095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_item.expected_text_query_extraction, 4105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_item.would_perform_search_term_replacement, 4115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_item.should_display_url); 4125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Disabling URL replacement should reset to only showing URLs. 4155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) browser()->toolbar_model()->set_url_replacement_enabled(false); 4165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) for (size_t i = 0; i < arraysize(test_items); ++i) { 4175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const TestItem& test_item = test_items[i]; 4185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NavigateAndCheckText(test_item.url, 4195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_item.expected_text_url_replacement_inactive, 4205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) false, test_item.should_display_url); 4215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 423