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

Unified Diff: components/omnibox/browser/omnibox_edit_unittest.cc

Issue 2048693003: Misc. omnibox cleanup: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resync Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/omnibox/browser/omnibox_edit_model.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/omnibox/browser/omnibox_edit_unittest.cc
diff --git a/components/omnibox/browser/omnibox_edit_unittest.cc b/components/omnibox/browser/omnibox_edit_unittest.cc
index 5c18fa6931a21ee0b7c63e42bfea08d468b7da06..f6e932ab45596e813a980e2db3ece28118ea6858 100644
--- a/components/omnibox/browser/omnibox_edit_unittest.cc
+++ b/components/omnibox/browser/omnibox_edit_unittest.cc
@@ -11,6 +11,7 @@
#include "components/omnibox/browser/autocomplete_classifier.h"
#include "components/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/browser/autocomplete_scheme_classifier.h"
+#include "components/omnibox/browser/history_url_provider.h"
#include "components/omnibox/browser/mock_autocomplete_provider_client.h"
#include "components/omnibox/browser/omnibox_client.h"
#include "components/omnibox/browser/omnibox_edit_controller.h"
@@ -23,9 +24,6 @@
#include "components/toolbar/test_toolbar_model.h"
#include "testing/gtest/include/gtest/gtest.h"
-using base::ASCIIToUTF16;
-using base::UTF8ToUTF16;
-
namespace {
class TestingOmniboxView : public OmniboxView {
@@ -80,8 +78,8 @@ class TestingOmniboxView : public OmniboxView {
bool OnAfterPossibleChange(bool allow_keyword_ui_change) override {
return false;
}
- gfx::NativeView GetNativeView() const override { return NULL; }
- gfx::NativeView GetRelativeWindowForPopup() const override { return NULL; }
+ gfx::NativeView GetNativeView() const override { return nullptr; }
+ gfx::NativeView GetRelativeWindowForPopup() const override { return nullptr; }
void SetGrayTextAutocompletion(const base::string16& input) override {}
base::string16 GetGrayTextAutocompletion() const override {
return base::string16();
@@ -246,11 +244,24 @@ TestingOmniboxClient::CreateAutocompleteProviderClient() {
class OmniboxEditTest : public ::testing::Test {
public:
+ OmniboxEditTest()
+ : controller_(&toolbar_model_),
+ view_(&controller_),
+ model_(&view_, &controller_, base::MakeUnique<TestingOmniboxClient>()) {
+ }
+
TestToolbarModel* toolbar_model() { return &toolbar_model_; }
+ const TestingOmniboxView& view() { return view_; }
+ OmniboxEditModel* model() { return &model_; }
private:
base::MessageLoop message_loop_;
TestToolbarModel toolbar_model_;
+ TestingOmniboxEditController controller_;
+ TestingOmniboxView view_;
+ OmniboxEditModel model_;
+
+ DISALLOW_COPY_AND_ASSIGN(OmniboxEditTest);
};
// Tests various permutations of AutocompleteModel::AdjustTextForCopy.
@@ -307,24 +318,21 @@ TEST_F(OmniboxEditTest, AdjustTextForCopy) {
{ "www.google.com/webhp?", 0, true, "hello world", "hello world", false,
"", true },
};
- TestingOmniboxEditController controller(toolbar_model());
- TestingOmniboxView view(&controller);
- OmniboxEditModel model(&view, &controller,
- base::WrapUnique(new TestingOmniboxClient()));
for (size_t i = 0; i < arraysize(input); ++i) {
- toolbar_model()->set_text(ASCIIToUTF16(input[i].perm_text));
- model.UpdatePermanentText();
+ toolbar_model()->set_text(base::ASCIIToUTF16(input[i].perm_text));
+ model()->UpdatePermanentText();
toolbar_model()->set_perform_search_term_replacement(
input[i].extracted_search_terms);
- base::string16 result = ASCIIToUTF16(input[i].input);
+ base::string16 result = base::ASCIIToUTF16(input[i].input);
GURL url;
bool write_url;
- model.AdjustTextForCopy(input[i].sel_start, input[i].is_all_selected,
- &result, &url, &write_url);
- EXPECT_EQ(ASCIIToUTF16(input[i].expected_output), result) << "@: " << i;
+ model()->AdjustTextForCopy(input[i].sel_start, input[i].is_all_selected,
+ &result, &url, &write_url);
+ EXPECT_EQ(base::ASCIIToUTF16(input[i].expected_output), result) << "@: "
+ << i;
EXPECT_EQ(input[i].write_url, write_url) << " @" << i;
if (write_url)
EXPECT_EQ(input[i].expected_url, url.spec()) << " @" << i;
@@ -332,38 +340,36 @@ TEST_F(OmniboxEditTest, AdjustTextForCopy) {
}
TEST_F(OmniboxEditTest, InlineAutocompleteText) {
- TestingOmniboxEditController controller(toolbar_model());
- TestingOmniboxView view(&controller);
- OmniboxEditModel model(&view, &controller,
- base::WrapUnique(new TestingOmniboxClient()));
-
// Test if the model updates the inline autocomplete text in the view.
- EXPECT_EQ(base::string16(), view.inline_autocomplete_text());
- model.SetUserText(UTF8ToUTF16("he"));
- model.OnPopupDataChanged(UTF8ToUTF16("llo"), NULL, base::string16(), false);
- EXPECT_EQ(UTF8ToUTF16("hello"), view.GetText());
- EXPECT_EQ(UTF8ToUTF16("llo"), view.inline_autocomplete_text());
-
- base::string16 text_before = UTF8ToUTF16("he");
- base::string16 text_after = UTF8ToUTF16("hel");
+ EXPECT_EQ(base::string16(), view().inline_autocomplete_text());
+ model()->SetUserText(base::ASCIIToUTF16("he"));
+ model()->OnPopupDataChanged(base::ASCIIToUTF16("llo"), nullptr,
+ base::string16(), false);
+ EXPECT_EQ(base::ASCIIToUTF16("hello"), view().GetText());
+ EXPECT_EQ(base::ASCIIToUTF16("llo"), view().inline_autocomplete_text());
+
+ base::string16 text_before = base::ASCIIToUTF16("he");
+ base::string16 text_after = base::ASCIIToUTF16("hel");
OmniboxView::StateChanges state_changes{
&text_before, &text_after, 3, 3, false, true, false, false};
- model.OnAfterPossibleChange(state_changes, true);
- EXPECT_EQ(base::string16(), view.inline_autocomplete_text());
- model.OnPopupDataChanged(UTF8ToUTF16("lo"), NULL, base::string16(), false);
- EXPECT_EQ(UTF8ToUTF16("hello"), view.GetText());
- EXPECT_EQ(UTF8ToUTF16("lo"), view.inline_autocomplete_text());
-
- model.Revert();
- EXPECT_EQ(base::string16(), view.GetText());
- EXPECT_EQ(base::string16(), view.inline_autocomplete_text());
-
- model.SetUserText(UTF8ToUTF16("he"));
- model.OnPopupDataChanged(UTF8ToUTF16("llo"), NULL, base::string16(), false);
- EXPECT_EQ(UTF8ToUTF16("hello"), view.GetText());
- EXPECT_EQ(UTF8ToUTF16("llo"), view.inline_autocomplete_text());
-
- model.AcceptTemporaryTextAsUserText();
- EXPECT_EQ(UTF8ToUTF16("hello"), view.GetText());
- EXPECT_EQ(base::string16(), view.inline_autocomplete_text());
+ model()->OnAfterPossibleChange(state_changes, true);
+ EXPECT_EQ(base::string16(), view().inline_autocomplete_text());
+ model()->OnPopupDataChanged(base::ASCIIToUTF16("lo"), nullptr,
+ base::string16(), false);
+ EXPECT_EQ(base::ASCIIToUTF16("hello"), view().GetText());
+ EXPECT_EQ(base::ASCIIToUTF16("lo"), view().inline_autocomplete_text());
+
+ model()->Revert();
+ EXPECT_EQ(base::string16(), view().GetText());
+ EXPECT_EQ(base::string16(), view().inline_autocomplete_text());
+
+ model()->SetUserText(base::ASCIIToUTF16("he"));
+ model()->OnPopupDataChanged(base::ASCIIToUTF16("llo"), nullptr,
+ base::string16(), false);
+ EXPECT_EQ(base::ASCIIToUTF16("hello"), view().GetText());
+ EXPECT_EQ(base::ASCIIToUTF16("llo"), view().inline_autocomplete_text());
+
+ model()->AcceptTemporaryTextAsUserText();
+ EXPECT_EQ(base::ASCIIToUTF16("hello"), view().GetText());
+ EXPECT_EQ(base::string16(), view().inline_autocomplete_text());
}
« no previous file with comments | « components/omnibox/browser/omnibox_edit_model.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698