| Index: chrome/browser/ui/views/omnibox/omnibox_view_views_unittest.cc
|
| diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views_unittest.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views_unittest.cc
|
| index 9e71b12b2a3c835d89eccb5c99747b85682504ba..9d5e1e965f3bbdc61e2bdff0ba67a2769cfda8cc 100644
|
| --- a/chrome/browser/ui/views/omnibox/omnibox_view_views_unittest.cc
|
| +++ b/chrome/browser/ui/views/omnibox/omnibox_view_views_unittest.cc
|
| @@ -10,12 +10,15 @@
|
|
|
| #include "base/macros.h"
|
| #include "build/build_config.h"
|
| +#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
|
| #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
|
| #include "chrome/browser/command_updater.h"
|
| +#include "chrome/browser/search_engines/template_url_service_factory_test_util.h"
|
| #include "chrome/browser/ui/omnibox/chrome_omnibox_client.h"
|
| #include "chrome/browser/ui/omnibox/chrome_omnibox_edit_controller.h"
|
| #include "chrome/test/base/testing_profile.h"
|
| #include "components/omnibox/browser/omnibox_edit_model.h"
|
| +#include "components/toolbar/test_toolbar_model.h"
|
| #include "content/public/test/test_browser_thread_bundle.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "ui/base/ime/text_edit_commands.h"
|
| @@ -55,15 +58,6 @@ class TestingOmniboxViewViews : public OmniboxViewViews {
|
| void SetEmphasis(bool emphasize, const gfx::Range& range) override;
|
| void UpdateSchemeStyle(const gfx::Range& range) override;
|
|
|
| - // Simplistic test override returns whether a given string looks like a URL
|
| - // without having to mock AutocompleteClassifier objects and their
|
| - // dependencies.
|
| - bool CurrentTextIsURL() override {
|
| - bool looks_like_url = (text().find(':') != std::string::npos ||
|
| - text().find('/') != std::string::npos);
|
| - return looks_like_url;
|
| - }
|
| -
|
| size_t update_popup_call_count_;
|
| base::string16 update_popup_text_;
|
| gfx::Range update_popup_selection_range_;
|
| @@ -131,17 +125,23 @@ void TestingOmniboxViewViews::UpdateSchemeStyle(const gfx::Range& range) {
|
|
|
| class TestingOmniboxEditController : public ChromeOmniboxEditController {
|
| public:
|
| - explicit TestingOmniboxEditController(CommandUpdater* command_updater)
|
| - : ChromeOmniboxEditController(command_updater) {}
|
| + TestingOmniboxEditController(CommandUpdater* command_updater,
|
| + ToolbarModel* toolbar_model)
|
| + : ChromeOmniboxEditController(command_updater),
|
| + toolbar_model_(toolbar_model) {}
|
|
|
| private:
|
| // ChromeOmniboxEditController:
|
| void UpdateWithoutTabRestore() override {}
|
| void OnChanged() override {}
|
| - ToolbarModel* GetToolbarModel() override { return nullptr; }
|
| - const ToolbarModel* GetToolbarModel() const override { return nullptr; }
|
| + ToolbarModel* GetToolbarModel() override { return toolbar_model_; }
|
| + const ToolbarModel* GetToolbarModel() const override {
|
| + return toolbar_model_;
|
| + }
|
| content::WebContents* GetWebContents() override { return nullptr; }
|
|
|
| + ToolbarModel* toolbar_model_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(TestingOmniboxEditController);
|
| };
|
|
|
| @@ -159,8 +159,11 @@ class OmniboxViewViewsTest : public testing::Test {
|
| return test_api_->scheduled_text_edit_command();
|
| }
|
|
|
| - // Sets |new_text| as the text in the omnibox.
|
| - void SetAndEmphasizeText(const std::string& new_text);
|
| + // Sets |new_text| as the text in the omnibox. If |accept_input| is true,
|
| + // pretends that the user has accepted this input (i.e. it's been navigated
|
| + // to).
|
| + void SetAndEmphasizeText(const std::string& new_text,
|
| + bool accept_input = true);
|
|
|
| private:
|
| // testing::Test:
|
| @@ -169,7 +172,9 @@ class OmniboxViewViewsTest : public testing::Test {
|
|
|
| content::TestBrowserThreadBundle thread_bundle_;
|
| TestingProfile profile_;
|
| + TemplateURLServiceFactoryTestUtil util_;
|
| CommandUpdater command_updater_;
|
| + TestToolbarModel toolbar_model_;
|
| TestingOmniboxEditController omnibox_edit_controller_;
|
| std::unique_ptr<TestingOmniboxViewViews> omnibox_view_;
|
| std::unique_ptr<views::TextfieldTestApi> test_api_;
|
| @@ -178,10 +183,19 @@ class OmniboxViewViewsTest : public testing::Test {
|
| };
|
|
|
| OmniboxViewViewsTest::OmniboxViewViewsTest()
|
| - : command_updater_(nullptr), omnibox_edit_controller_(&command_updater_) {}
|
| -
|
| -void OmniboxViewViewsTest::SetAndEmphasizeText(const std::string& new_text) {
|
| - omnibox_view()->SetText(base::ASCIIToUTF16(new_text));
|
| + : util_(&profile_),
|
| + command_updater_(nullptr),
|
| + omnibox_edit_controller_(&command_updater_, &toolbar_model_) {}
|
| +
|
| +void OmniboxViewViewsTest::SetAndEmphasizeText(const std::string& new_text,
|
| + bool accept_input) {
|
| + omnibox_view()->SetUserText(base::ASCIIToUTF16(new_text));
|
| + if (accept_input) {
|
| + // We don't need to actually navigate in this case (and doing so in a test
|
| + // would be difficult); it's sufficient to mark input as "no longer in
|
| + // progress", and the edit model will assume the current text is a URL.
|
| + omnibox_view()->model()->SetInputInProgress(false);
|
| + }
|
| omnibox_view()->EmphasizeURLComponents();
|
| }
|
|
|
| @@ -190,6 +204,8 @@ void OmniboxViewViewsTest::SetUp() {
|
| chromeos::input_method::InitializeForTesting(
|
| new chromeos::input_method::MockInputMethodManagerImpl);
|
| #endif
|
| + AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse(
|
| + &profile_, &AutocompleteClassifierFactory::BuildInstanceFor);
|
| omnibox_view_ = base::MakeUnique<TestingOmniboxViewViews>(
|
| &omnibox_edit_controller_,
|
| base::MakeUnique<ChromeOmniboxClient>(&omnibox_edit_controller_,
|
| @@ -246,7 +262,7 @@ TEST_F(OmniboxViewViewsTest, ScheduledTextEditCommand) {
|
| }
|
|
|
| // Ensure that the scheme is emphasized for data: URLs.
|
| -TEST_F(OmniboxViewViewsTest, TestEmphasisForDATA) {
|
| +TEST_F(OmniboxViewViewsTest, TestEmphasisForData) {
|
| SetAndEmphasizeText("data:text/html,Hello%20World");
|
| EXPECT_EQ(gfx::Range(0, 4), omnibox_view()->scheme_range());
|
| EXPECT_FALSE(omnibox_view()->base_text_is_emphasized());
|
| @@ -270,7 +286,7 @@ TEST_F(OmniboxViewViewsTest, TestEmphasisForHTTPS) {
|
| }
|
|
|
| // Ensure that nothing is emphasized for chrome-extension: URLs.
|
| -TEST_F(OmniboxViewViewsTest, TestEmphasisForChromeExtensionScheme) {
|
| +TEST_F(OmniboxViewViewsTest, TestEmphasisForChromeExtension) {
|
| SetAndEmphasizeText("chrome-extension://ldfbacdbackkjhclmhnjabngnppnkagl");
|
| EXPECT_EQ(gfx::Range(0, 16), omnibox_view()->scheme_range());
|
| EXPECT_FALSE(omnibox_view()->base_text_is_emphasized());
|
| @@ -295,15 +311,15 @@ TEST_F(OmniboxViewViewsTest, TestEmphasisForUnknownScheme) {
|
|
|
| // Ensure that the origin is emphasized for URL-like text.
|
| TEST_F(OmniboxViewViewsTest, TestEmphasisForPartialURLs) {
|
| - SetAndEmphasizeText("example/path/file");
|
| + SetAndEmphasizeText("host.com/path/file", false);
|
| EXPECT_EQ(gfx::Range(), omnibox_view()->scheme_range());
|
| EXPECT_FALSE(omnibox_view()->base_text_is_emphasized());
|
| - EXPECT_EQ(gfx::Range(0, 7), omnibox_view()->emphasis_range());
|
| + EXPECT_EQ(gfx::Range(0, 8), omnibox_view()->emphasis_range());
|
| }
|
|
|
| // Ensure that everything is emphasized for plain text.
|
| TEST_F(OmniboxViewViewsTest, TestEmphasisForNonURLs) {
|
| - SetAndEmphasizeText("This is plain text");
|
| + SetAndEmphasizeText("This is plain text", false);
|
|
|
| EXPECT_EQ(gfx::Range(), omnibox_view()->scheme_range());
|
| EXPECT_TRUE(omnibox_view()->base_text_is_emphasized());
|
|
|