summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlliabraa@chromium.org <lliabraa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-11 21:32:41 +0000
committerlliabraa@chromium.org <lliabraa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-11 21:32:41 +0000
commit736d0032d2e728aea07d274a3ab9056729c349cf (patch)
tree47820330e5e5b96db341f3e2d51985c0dde5b4d0
parentc8159ad1f1704aab033489d8779e7d9f046bb3bf (diff)
downloadchromium_src-736d0032d2e728aea07d274a3ab9056729c349cf.zip
chromium_src-736d0032d2e728aea07d274a3ab9056729c349cf.tar.gz
chromium_src-736d0032d2e728aea07d274a3ab9056729c349cf.tar.bz2
Adds a FakeToolbarModel for use in testing.
The ToolbarModel's dependencies make it hard to include in unit tests. This simple fake is created with some default values which can be changed via the setters. BUG=None Review URL: https://chromiumcodereview.appspot.com/11040055 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161407 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/login/simple_web_view_dialog.cc4
-rw-r--r--chrome/browser/ui/browser.cc3
-rw-r--r--chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm12
-rw-r--r--chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm2
-rw-r--r--chrome/browser/ui/gtk/location_bar_view_gtk.cc17
-rw-r--r--chrome/browser/ui/search/toolbar_search_animator.cc2
-rw-r--r--chrome/browser/ui/toolbar/test_toolbar_model.cc52
-rw-r--r--chrome/browser/ui/toolbar/test_toolbar_model.h59
-rw-r--r--chrome/browser/ui/toolbar/toolbar_model.h55
-rw-r--r--chrome/browser/ui/toolbar/toolbar_model_impl.cc (renamed from chrome/browser/ui/toolbar/toolbar_model.cc)43
-rw-r--r--chrome/browser/ui/toolbar/toolbar_model_impl.h72
-rw-r--r--chrome/browser/ui/views/location_bar/location_bar_view.cc12
-rw-r--r--chrome/browser/ui/views/location_bar/zoom_view.cc2
-rw-r--r--chrome/browser/ui/views/toolbar_view.cc4
-rw-r--r--chrome/chrome_browser_ui.gypi3
-rw-r--r--chrome/chrome_tests.gypi2
16 files changed, 257 insertions, 87 deletions
diff --git a/chrome/browser/chromeos/login/simple_web_view_dialog.cc b/chrome/browser/chromeos/login/simple_web_view_dialog.cc
index c9d9ca9..3f6f82d 100644
--- a/chrome/browser/chromeos/login/simple_web_view_dialog.cc
+++ b/chrome/browser/chromeos/login/simple_web_view_dialog.cc
@@ -14,7 +14,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/content_settings/content_setting_bubble_model_delegate.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
-#include "chrome/browser/ui/toolbar/toolbar_model.h"
+#include "chrome/browser/ui/toolbar/toolbar_model_impl.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/location_bar/location_icon_view.h"
#include "chrome/browser/ui/views/page_info_bubble_view.h"
@@ -179,7 +179,7 @@ void SimpleWebViewDialog::Init() {
forward_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FORWARD));
forward_->set_id(VIEW_ID_FORWARD_BUTTON);
- toolbar_model_.reset(new ToolbarModel(this));
+ toolbar_model_.reset(new ToolbarModelImpl(this));
// Location bar.
location_bar_ = new LocationBarView(NULL,
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index 3e52fb2..12e0fa6 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -135,6 +135,7 @@
#include "chrome/browser/ui/tabs/dock_info.h"
#include "chrome/browser/ui/tabs/tab_menu_model.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/toolbar/toolbar_model_impl.h"
#include "chrome/browser/ui/unload_controller.h"
#include "chrome/browser/ui/web_applications/web_app_ui.h"
#include "chrome/browser/ui/webui/signin/login_ui_service.h"
@@ -364,7 +365,7 @@ Browser::Browser(const CreateParams& params)
chrome::RegisterAppPrefs(app_name_, profile_);
tab_strip_model_->AddObserver(this);
- toolbar_model_.reset(new ToolbarModel(toolbar_model_delegate_.get()));
+ toolbar_model_.reset(new ToolbarModelImpl(toolbar_model_delegate_.get()));
search_model_.reset(new chrome::search::SearchModel(NULL));
search_delegate_.reset(
new chrome::search::SearchDelegate(search_model_.get(),
diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
index 8dcccec..cb95413 100644
--- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
+++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
@@ -316,7 +316,7 @@ void LocationBarViewMac::OnSelectionBoundsChanged() {
}
void LocationBarViewMac::OnInputInProgress(bool in_progress) {
- toolbar_model_->set_input_in_progress(in_progress);
+ toolbar_model_->SetInputInProgress(in_progress);
Update(NULL, false);
}
@@ -616,7 +616,7 @@ void LocationBarViewMac::PostNotification(NSString* notification) {
}
bool LocationBarViewMac::RefreshContentSettingsDecorations() {
- const bool input_in_progress = toolbar_model_->input_in_progress();
+ const bool input_in_progress = toolbar_model_->GetInputInProgress();
WebContents* web_contents =
input_in_progress ? NULL : chrome::GetActiveWebContents(browser_);
bool icons_updated = false;
@@ -664,7 +664,7 @@ void LocationBarViewMac::RefreshPageActionDecorations() {
GURL url = toolbar_model_->GetURL();
for (size_t i = 0; i < page_action_decorations_.size(); ++i) {
page_action_decorations_[i]->UpdateVisibility(
- toolbar_model_->input_in_progress() ?
+ toolbar_model_->GetInputInProgress() ?
NULL : tab_contents->web_contents(),
url);
}
@@ -764,7 +764,7 @@ void LocationBarViewMac::RedrawDecoration(LocationBarDecoration* decoration) {
bool LocationBarViewMac::IsStarEnabled() {
return [field_ isEditable] &&
browser_defaults::bookmarks_enabled &&
- !toolbar_model_->input_in_progress() &&
+ !toolbar_model_->GetInputInProgress() &&
edit_bookmarks_enabled_.GetValue();
}
@@ -772,7 +772,7 @@ void LocationBarViewMac::UpdateChromeToMobileEnabled() {
ChromeToMobileService* chrome_to_mobile_service =
ChromeToMobileServiceFactory::GetForProfile(profile_);
command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE,
- [field_ isEditable] && !toolbar_model_->input_in_progress() &&
+ [field_ isEditable] && !toolbar_model_->GetInputInProgress() &&
chrome_to_mobile_service && chrome_to_mobile_service->HasMobiles());
}
@@ -798,6 +798,6 @@ void LocationBarViewMac::UpdateStarDecorationVisibility() {
void LocationBarViewMac::UpdatePlusDecorationVisibility() {
if (extensions::switch_utils::IsActionBoxEnabled()) {
// If the action box is enabled, hide it when input is in progress.
- plus_decoration_->SetVisible(!toolbar_model_->input_in_progress());
+ plus_decoration_->SetVisible(!toolbar_model_->GetInputInProgress());
}
}
diff --git a/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm b/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm
index d6dedc1..6e0e4a0 100644
--- a/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm
+++ b/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm
@@ -23,7 +23,7 @@ ZoomDecoration::~ZoomDecoration() {
void ZoomDecoration::Update(ZoomController* zoom_controller) {
if (!zoom_controller || zoom_controller->IsAtDefaultZoom() ||
- toolbar_model_->input_in_progress()) {
+ toolbar_model_->GetInputInProgress()) {
// TODO(dbeam): hide zoom bubble when it exists.
SetVisible(false);
return;
diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.cc b/chrome/browser/ui/gtk/location_bar_view_gtk.cc
index 68bdedd..cfc5ac2 100644
--- a/chrome/browser/ui/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/ui/gtk/location_bar_view_gtk.cc
@@ -860,9 +860,9 @@ void LocationBarViewGtk::OnInputInProgress(bool in_progress) {
// This is identical to the Windows code, except that we don't proxy the call
// back through the Toolbar, and just access the model here.
// The edit should make sure we're only notified when something changes.
- DCHECK(toolbar_model_->input_in_progress() != in_progress);
+ DCHECK(toolbar_model_->GetInputInProgress() != in_progress);
- toolbar_model_->set_input_in_progress(in_progress);
+ toolbar_model_->SetInputInProgress(in_progress);
Update(NULL);
}
@@ -948,7 +948,7 @@ void LocationBarViewGtk::UpdateContentSettingsIcons() {
content_setting_views_.begin());
i != content_setting_views_.end(); ++i) {
(*i)->Update(
- toolbar_model_->input_in_progress() ? NULL : GetTabContents());
+ toolbar_model_->GetInputInProgress() ? NULL : GetTabContents());
any_visible = (*i)->IsVisible() || any_visible;
}
@@ -991,7 +991,7 @@ void LocationBarViewGtk::UpdatePageActions() {
for (size_t i = 0; i < page_action_views_.size(); i++) {
page_action_views_[i]->UpdateVisibility(
- toolbar_model_->input_in_progress() ? NULL : contents, url);
+ toolbar_model_->GetInputInProgress() ? NULL : contents, url);
}
gtk_widget_queue_draw(hbox_.get());
}
@@ -1536,7 +1536,7 @@ gboolean LocationBarViewGtk::OnStarButtonPress(GtkWidget* widget,
}
void LocationBarViewGtk::ShowZoomBubble() {
- if (!zoom_.get() || toolbar_model_->input_in_progress())
+ if (!zoom_.get() || toolbar_model_->GetInputInProgress())
return;
ZoomBubbleGtk::Show(zoom_.get(), GetTabContents(), true);
@@ -1584,7 +1584,7 @@ void LocationBarViewGtk::UpdateZoomIcon() {
ZoomController* zoom_controller =
ZoomController::FromWebContents(tab_contents->web_contents());
if (!zoom_controller || zoom_controller->IsAtDefaultZoom() ||
- toolbar_model_->input_in_progress()) {
+ toolbar_model_->GetInputInProgress()) {
gtk_widget_hide(zoom_.get());
ZoomBubbleGtk::Close();
return;
@@ -1607,7 +1607,7 @@ void LocationBarViewGtk::UpdateStarIcon() {
// Indicate the star icon is not correctly sized. It will be marked as sized
// when the next size-allocate signal is received by the star widget.
star_sized_ = false;
- bool star_enabled = !toolbar_model_->input_in_progress() &&
+ bool star_enabled = !toolbar_model_->GetInputInProgress() &&
edit_bookmarks_enabled_.GetValue();
command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled);
if (extensions::switch_utils::IsActionBoxEnabled() && !starred_) {
@@ -1627,7 +1627,8 @@ void LocationBarViewGtk::UpdateChromeToMobileState() {
ChromeToMobileService* service =
ChromeToMobileServiceFactory::GetForProfile(browser()->profile());
command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE,
- !toolbar_model_->input_in_progress() && service && service->HasMobiles());
+ !toolbar_model_->GetInputInProgress() &&
+ service && service->HasMobiles());
}
bool LocationBarViewGtk::ShouldOnlyShowLocation() {
diff --git a/chrome/browser/ui/search/toolbar_search_animator.cc b/chrome/browser/ui/search/toolbar_search_animator.cc
index 46af7cb..b33bb14 100644
--- a/chrome/browser/ui/search/toolbar_search_animator.cc
+++ b/chrome/browser/ui/search/toolbar_search_animator.cc
@@ -54,7 +54,7 @@ bool ToolbarSearchAnimator::IsToolbarSeparatorVisible() const {
// 2) when mode is |DEFAULT| and the omnibox popup has finished retracting.
return !is_omnibox_popup_open_ &&
((search_model_->mode().mode == Mode::MODE_SEARCH_SUGGESTIONS &&
- !toolbar_model_->input_in_progress()) ||
+ !toolbar_model_->GetInputInProgress()) ||
search_model_->mode().is_default());
}
diff --git a/chrome/browser/ui/toolbar/test_toolbar_model.cc b/chrome/browser/ui/toolbar/test_toolbar_model.cc
new file mode 100644
index 0000000..7864e3a
--- /dev/null
+++ b/chrome/browser/ui/toolbar/test_toolbar_model.cc
@@ -0,0 +1,52 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/toolbar/test_toolbar_model.h"
+
+TestToolbarModel::TestToolbarModel()
+ : ToolbarModel(),
+ should_replace_url_(false),
+ security_level_(NONE),
+ icon_(0),
+ should_display_url_(true),
+ input_in_progress_(false) {}
+
+TestToolbarModel::~TestToolbarModel() {}
+
+string16 TestToolbarModel::GetText(
+ bool display_search_urls_as_search_terms) const {
+ return text_;
+}
+
+GURL TestToolbarModel::GetURL() const {
+ return url_;
+}
+
+bool TestToolbarModel::WouldReplaceSearchURLWithSearchTerms() const {
+ return should_replace_url_;
+}
+
+ToolbarModel::SecurityLevel TestToolbarModel::GetSecurityLevel() const {
+ return security_level_;
+}
+
+int TestToolbarModel::GetIcon() const {
+ return icon_;
+}
+
+string16 TestToolbarModel::GetEVCertName() const {
+ return ev_cert_name_;
+}
+
+bool TestToolbarModel::ShouldDisplayURL() const {
+ return should_display_url_;
+}
+
+void TestToolbarModel::SetInputInProgress(bool value) {
+ input_in_progress_ = value;
+}
+
+bool TestToolbarModel::GetInputInProgress() const {
+ return input_in_progress_;
+}
diff --git a/chrome/browser/ui/toolbar/test_toolbar_model.h b/chrome/browser/ui/toolbar/test_toolbar_model.h
new file mode 100644
index 0000000..2af526d
--- /dev/null
+++ b/chrome/browser/ui/toolbar/test_toolbar_model.h
@@ -0,0 +1,59 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_TOOLBAR_TEST_TOOLBAR_MODEL_H_
+#define CHROME_BROWSER_UI_TOOLBAR_TEST_TOOLBAR_MODEL_H_
+
+#include "base/compiler_specific.h"
+#include "base/string16.h"
+#include "chrome/browser/ui/toolbar/toolbar_model.h"
+
+// A ToolbarModel that is backed by instance variables, which are initialized
+// with some basic values that can be changed with the provided setters. This
+// should be used only for testing.
+class TestToolbarModel : public ToolbarModel {
+ public:
+ TestToolbarModel();
+ virtual ~TestToolbarModel();
+ virtual string16 GetText(
+ bool display_search_urls_as_search_terms) const OVERRIDE;
+ virtual GURL GetURL() const OVERRIDE;
+ virtual bool WouldReplaceSearchURLWithSearchTerms() const OVERRIDE;
+ virtual SecurityLevel GetSecurityLevel() const OVERRIDE;
+ virtual int GetIcon() const OVERRIDE;
+ virtual string16 GetEVCertName() const OVERRIDE;
+ virtual bool ShouldDisplayURL() const OVERRIDE;
+ virtual void SetInputInProgress(bool value) OVERRIDE;
+ virtual bool GetInputInProgress() const OVERRIDE;
+
+ void set_text(const string16& text) { text_ = text; }
+ void set_url(const GURL& url) { url_ = url;}
+ void set_replace_search_url_with_search_terms(bool should_replace_url) {
+ should_replace_url_ = should_replace_url;
+ }
+ void set_security_level(SecurityLevel security_level) {
+ security_level_ = security_level;
+ }
+ void set_icon(int icon) { icon_ = icon; }
+ void set_ev_cert_name(const string16& ev_cert_name) {
+ ev_cert_name_ = ev_cert_name;
+ }
+ void set_should_display_url(bool should_display_url) {
+ should_display_url_ = should_display_url;
+ }
+
+ private:
+ string16 text_;
+ GURL url_;
+ bool should_replace_url_;
+ SecurityLevel security_level_;
+ int icon_;
+ string16 ev_cert_name_;
+ bool should_display_url_;
+ bool input_in_progress_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestToolbarModel);
+};
+
+#endif // CHROME_BROWSER_UI_TOOLBAR_TEST_TOOLBAR_MODEL_H_
diff --git a/chrome/browser/ui/toolbar/toolbar_model.h b/chrome/browser/ui/toolbar/toolbar_model.h
index 939ad2e..e25e66e 100644
--- a/chrome/browser/ui/toolbar/toolbar_model.h
+++ b/chrome/browser/ui/toolbar/toolbar_model.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,13 +11,6 @@
#include "base/string16.h"
#include "googleurl/src/gurl.h"
-class Profile;
-class ToolbarModelDelegate;
-
-namespace content {
-class NavigationController;
-}
-
namespace net {
class X509Certificate;
}
@@ -40,8 +33,7 @@ class ToolbarModel {
NUM_SECURITY_LEVELS,
};
- explicit ToolbarModel(ToolbarModelDelegate* delegate);
- ~ToolbarModel();
+ virtual ~ToolbarModel() {}
// Returns the text for the current page's URL. This will have been formatted
// for display to the user:
@@ -50,59 +42,38 @@ class ToolbarModel {
// - if |display_search_urls_as_search_terms| is true, the query will be
// extracted from search URLs for the user's default search engine and those
// will be displayed in place of the URL.
- string16 GetText(bool display_search_urls_as_search_terms) const;
+ virtual string16 GetText(bool display_search_urls_as_search_terms) const = 0;
// Returns the URL of the current navigation entry.
- GURL GetURL() const;
+ virtual GURL GetURL() const = 0;
// Returns true if a call to GetText(true) would successfully replace the URL
// with search terms.
- bool WouldReplaceSearchURLWithSearchTerms() const;
+ virtual bool WouldReplaceSearchURLWithSearchTerms() const = 0;
// Returns the security level that the toolbar should display.
- SecurityLevel GetSecurityLevel() const;
+ virtual SecurityLevel GetSecurityLevel() const = 0;
// Returns the resource_id of the icon to show to the left of the address,
// based on the current URL. This doesn't cover specialized icons while the
// user is editing; see OmniboxView::GetIcon().
- int GetIcon() const;
+ virtual int GetIcon() const = 0;
// Returns the name of the EV cert holder. Only call this when the security
// level is EV_SECURE.
- string16 GetEVCertName() const;
+ virtual string16 GetEVCertName() const = 0;
// Returns whether the URL for the current navigation entry should be
// in the location bar.
- bool ShouldDisplayURL() const;
+ virtual bool ShouldDisplayURL() const = 0;
// Getter/setter of whether the text in location bar is currently being
// edited.
- void set_input_in_progress(bool value) { input_in_progress_ = value; }
- bool input_in_progress() const { return input_in_progress_; }
-
- // Returns "<organization_name> [<country>]".
- static string16 GetEVCertName(const net::X509Certificate& cert);
-
- private:
- // Returns the navigation controller used to retrieve the navigation entry
- // from which the states are retrieved.
- // If this returns NULL, default values are used.
- content::NavigationController* GetNavigationController() const;
-
- // Attempt to extract search terms from |url|. Called by GetText if
- // |display_search_urls_as_search_terms| is true and by
- // WouldReplaceSearchURLWithSearchTerms.
- string16 TryToExtractSearchTermsFromURL(const GURL& url) const;
-
- // Helper method to extract the profile from the navigation controller.
- Profile* GetProfile() const;
-
- ToolbarModelDelegate* delegate_;
-
- // Whether the text in the location bar is currently being edited.
- bool input_in_progress_;
+ virtual void SetInputInProgress(bool value) = 0;
+ virtual bool GetInputInProgress() const = 0;
- DISALLOW_IMPLICIT_CONSTRUCTORS(ToolbarModel);
+ protected:
+ ToolbarModel() {}
};
#endif // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_MODEL_H_
diff --git a/chrome/browser/ui/toolbar/toolbar_model.cc b/chrome/browser/ui/toolbar/toolbar_model_impl.cc
index 46efad6..96e0db3 100644
--- a/chrome/browser/ui/toolbar/toolbar_model.cc
+++ b/chrome/browser/ui/toolbar/toolbar_model_impl.cc
@@ -1,8 +1,8 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/ui/toolbar/toolbar_model.h"
+#include "chrome/browser/ui/toolbar/toolbar_model_impl.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete_input.h"
@@ -28,6 +28,7 @@
#include "grit/theme_resources.h"
#include "net/base/cert_status_flags.h"
#include "net/base/net_util.h"
+#include "net/base/x509_certificate.h"
#include "ui/base/l10n/l10n_util.h"
using content::NavigationController;
@@ -35,16 +36,17 @@ using content::NavigationEntry;
using content::SSLStatus;
using content::WebContents;
-ToolbarModel::ToolbarModel(ToolbarModelDelegate* delegate)
+ToolbarModelImpl::ToolbarModelImpl(ToolbarModelDelegate* delegate)
: delegate_(delegate),
input_in_progress_(false) {
}
-ToolbarModel::~ToolbarModel() {
+ToolbarModelImpl::~ToolbarModelImpl() {
}
-// ToolbarModel Implementation.
-string16 ToolbarModel::GetText(bool display_search_urls_as_search_terms) const {
+// ToolbarModelImpl Implementation.
+string16 ToolbarModelImpl::GetText(
+ bool display_search_urls_as_search_terms) const {
GURL url(GetURL());
if (display_search_urls_as_search_terms) {
@@ -67,7 +69,7 @@ string16 ToolbarModel::GetText(bool display_search_urls_as_search_terms) const {
net::UnescapeRule::NORMAL, NULL, NULL, NULL));
}
-GURL ToolbarModel::GetURL() const {
+GURL ToolbarModelImpl::GetURL() const {
const NavigationController* navigation_controller = GetNavigationController();
if (navigation_controller) {
const NavigationEntry* entry = navigation_controller->GetVisibleEntry();
@@ -78,11 +80,11 @@ GURL ToolbarModel::GetURL() const {
return GURL(chrome::kAboutBlankURL);
}
-bool ToolbarModel::WouldReplaceSearchURLWithSearchTerms() const {
+bool ToolbarModelImpl::WouldReplaceSearchURLWithSearchTerms() const {
return !TryToExtractSearchTermsFromURL(GetURL()).empty();
}
-bool ToolbarModel::ShouldDisplayURL() const {
+bool ToolbarModelImpl::ShouldDisplayURL() const {
// Note: The order here is important.
// - The WebUI test must come before the extension scheme test because there
// can be WebUIs that have extension schemes (e.g. the bookmark manager). In
@@ -114,7 +116,7 @@ bool ToolbarModel::ShouldDisplayURL() const {
return true;
}
-ToolbarModel::SecurityLevel ToolbarModel::GetSecurityLevel() const {
+ToolbarModelImpl::SecurityLevel ToolbarModelImpl::GetSecurityLevel() const {
if (input_in_progress_) // When editing, assume no security style.
return NONE;
@@ -153,7 +155,7 @@ ToolbarModel::SecurityLevel ToolbarModel::GetSecurityLevel() const {
}
}
-int ToolbarModel::GetIcon() const {
+int ToolbarModelImpl::GetIcon() const {
static int icon_ids[NUM_SECURITY_LEVELS] = {
IDR_LOCATION_BAR_HTTP,
IDR_OMNIBOX_HTTPS_VALID,
@@ -165,7 +167,7 @@ int ToolbarModel::GetIcon() const {
return icon_ids[GetSecurityLevel()];
}
-string16 ToolbarModel::GetEVCertName() const {
+string16 ToolbarModelImpl::GetEVCertName() const {
DCHECK_EQ(GetSecurityLevel(), EV_SECURE);
scoped_refptr<net::X509Certificate> cert;
// Note: Navigation controller and active entry are guaranteed non-NULL or
@@ -176,7 +178,7 @@ string16 ToolbarModel::GetEVCertName() const {
}
// static
-string16 ToolbarModel::GetEVCertName(const net::X509Certificate& cert) {
+string16 ToolbarModelImpl::GetEVCertName(const net::X509Certificate& cert) {
// EV are required to have an organization name and country.
if (cert.subject().organization_names.empty() ||
cert.subject().country_name.empty()) {
@@ -190,7 +192,15 @@ string16 ToolbarModel::GetEVCertName(const net::X509Certificate& cert) {
UTF8ToUTF16(cert.subject().country_name));
}
-NavigationController* ToolbarModel::GetNavigationController() const {
+void ToolbarModelImpl::SetInputInProgress(bool value) {
+ input_in_progress_ = value;
+}
+
+bool ToolbarModelImpl::GetInputInProgress() const {
+ return input_in_progress_;
+}
+
+NavigationController* ToolbarModelImpl::GetNavigationController() const {
// This |current_tab| can be NULL during the initialization of the
// toolbar during window creation (i.e. before any tabs have been added
// to the window).
@@ -198,7 +208,8 @@ NavigationController* ToolbarModel::GetNavigationController() const {
return current_tab ? &current_tab->GetController() : NULL;
}
-string16 ToolbarModel::TryToExtractSearchTermsFromURL(const GURL& url) const {
+string16 ToolbarModelImpl::TryToExtractSearchTermsFromURL(
+ const GURL& url) const {
Profile* profile = GetProfile();
// Ensure instant extended API is enabled.
@@ -217,7 +228,7 @@ string16 ToolbarModel::TryToExtractSearchTermsFromURL(const GURL& url) const {
return result;
}
-Profile* ToolbarModel::GetProfile() const {
+Profile* ToolbarModelImpl::GetProfile() const {
NavigationController* navigation_controller = GetNavigationController();
return navigation_controller ?
Profile::FromBrowserContext(navigation_controller->GetBrowserContext()) :
diff --git a/chrome/browser/ui/toolbar/toolbar_model_impl.h b/chrome/browser/ui/toolbar/toolbar_model_impl.h
new file mode 100644
index 0000000..e65efc3
--- /dev/null
+++ b/chrome/browser/ui/toolbar/toolbar_model_impl.h
@@ -0,0 +1,72 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_MODEL_IMPL_H_
+#define CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_MODEL_IMPL_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/string16.h"
+#include "chrome/browser/ui/toolbar/toolbar_model.h"
+#include "googleurl/src/gurl.h"
+
+class Profile;
+class ToolbarModelDelegate;
+
+namespace content {
+class NavigationController;
+}
+
+namespace net {
+class X509Certificate;
+}
+
+// This class is the model used by the toolbar, location bar and autocomplete
+// edit. It populates its states from the current navigation entry retrieved
+// from the navigation controller returned by GetNavigationController().
+class ToolbarModelImpl : public ToolbarModel {
+ public:
+ explicit ToolbarModelImpl(ToolbarModelDelegate* delegate);
+ virtual ~ToolbarModelImpl();
+
+ // Overriden from ToolbarModel.
+ virtual string16 GetText(
+ bool display_search_urls_as_search_terms) const OVERRIDE;
+ virtual GURL GetURL() const OVERRIDE;
+ virtual bool WouldReplaceSearchURLWithSearchTerms() const OVERRIDE;
+ virtual SecurityLevel GetSecurityLevel() const OVERRIDE;
+ virtual int GetIcon() const OVERRIDE;
+ virtual string16 GetEVCertName() const OVERRIDE;
+ virtual bool ShouldDisplayURL() const OVERRIDE;
+ virtual void SetInputInProgress(bool value) OVERRIDE;
+ virtual bool GetInputInProgress() const OVERRIDE;
+
+ // Returns "<organization_name> [<country>]".
+ static string16 GetEVCertName(const net::X509Certificate& cert);
+
+ private:
+ // Returns the navigation controller used to retrieve the navigation entry
+ // from which the states are retrieved.
+ // If this returns NULL, default values are used.
+ content::NavigationController* GetNavigationController() const;
+
+ // Attempt to extract search terms from |url|. Called by GetText if
+ // |display_search_urls_as_search_terms| is true and by
+ // WouldReplaceSearchURLWithSearchTerms.
+ string16 TryToExtractSearchTermsFromURL(const GURL& url) const;
+
+ // Helper method to extract the profile from the navigation controller.
+ Profile* GetProfile() const;
+
+ ToolbarModelDelegate* delegate_;
+
+ // Whether the text in the location bar is currently being edited.
+ bool input_in_progress_;
+
+ DISALLOW_IMPLICIT_CONSTRUCTORS(ToolbarModelImpl);
+};
+
+#endif // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_MODEL_IMPL_H_
diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc
index 730475d..0658c15 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.cc
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc
@@ -458,9 +458,9 @@ void LocationBarView::Update(const WebContents* tab_for_state_restoring) {
RefreshPageActionViews();
web_intents_button_view_->Update(GetTabContents());
open_pdf_in_reader_view_->Update(
- model_->input_in_progress() ? NULL : GetTabContents());
+ model_->GetInputInProgress() ? NULL : GetTabContents());
- bool star_enabled = star_view_ && !model_->input_in_progress() &&
+ bool star_enabled = star_view_ && !model_->GetInputInProgress() &&
edit_bookmarks_enabled_.GetValue();
command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled);
@@ -470,7 +470,7 @@ void LocationBarView::Update(const WebContents* tab_for_state_restoring) {
ChromeToMobileService* chrome_to_mobile_service =
ChromeToMobileServiceFactory::GetForProfile(profile_);
command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE,
- !model_->input_in_progress() && chrome_to_mobile_service &&
+ !model_->GetInputInProgress() && chrome_to_mobile_service &&
chrome_to_mobile_service->HasMobiles());
// Don't Update in app launcher mode so that the location entry does not show
@@ -521,7 +521,7 @@ void LocationBarView::UpdateWebIntentsButton() {
void LocationBarView::UpdateOpenPDFInReaderPrompt() {
open_pdf_in_reader_view_->Update(
- model_->input_in_progress() ? NULL : GetTabContents());
+ model_->GetInputInProgress() ? NULL : GetTabContents());
Layout();
SchedulePaint();
}
@@ -1224,7 +1224,7 @@ void LocationBarView::LayoutView(views::View* view,
void LocationBarView::RefreshContentSettingViews() {
for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
i != content_setting_views_.end(); ++i) {
- (*i)->Update(model_->input_in_progress() ? NULL : GetTabContents());
+ (*i)->Update(model_->GetInputInProgress() ? NULL : GetTabContents());
}
}
@@ -1288,7 +1288,7 @@ void LocationBarView::RefreshPageActionViews() {
for (PageActionViews::const_iterator i(page_action_views_.begin());
i != page_action_views_.end(); ++i) {
- (*i)->UpdateVisibility(model_->input_in_progress() ? NULL : contents,
+ (*i)->UpdateVisibility(model_->GetInputInProgress() ? NULL : contents,
url);
// Check if the visibility of the action changed and notify if it did.
diff --git a/chrome/browser/ui/views/location_bar/zoom_view.cc b/chrome/browser/ui/views/location_bar/zoom_view.cc
index a2f3149..c16e3b0 100644
--- a/chrome/browser/ui/views/location_bar/zoom_view.cc
+++ b/chrome/browser/ui/views/location_bar/zoom_view.cc
@@ -30,7 +30,7 @@ ZoomView::~ZoomView() {
void ZoomView::Update(ZoomController* zoom_controller) {
if (!zoom_controller || zoom_controller->IsAtDefaultZoom() ||
- toolbar_model_->input_in_progress()) {
+ toolbar_model_->GetInputInProgress()) {
SetVisible(false);
ZoomBubbleView::CloseBubble();
return;
diff --git a/chrome/browser/ui/views/toolbar_view.cc b/chrome/browser/ui/views/toolbar_view.cc
index 2e627b7..68a4931 100644
--- a/chrome/browser/ui/views/toolbar_view.cc
+++ b/chrome/browser/ui/views/toolbar_view.cc
@@ -521,9 +521,9 @@ PageActionImageView* ToolbarView::CreatePageActionImageView(
void ToolbarView::OnInputInProgress(bool in_progress) {
// The edit should make sure we're only notified when something changes.
- DCHECK(model_->input_in_progress() != in_progress);
+ DCHECK(model_->GetInputInProgress() != in_progress);
- model_->set_input_in_progress(in_progress);
+ model_->SetInputInProgress(in_progress);
location_bar_->Update(NULL);
}
diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi
index c89b7bb..4497ed1 100644
--- a/chrome/chrome_browser_ui.gypi
+++ b/chrome/chrome_browser_ui.gypi
@@ -1278,8 +1278,9 @@
'browser/ui/toolbar/bookmark_sub_menu_model.h',
'browser/ui/toolbar/encoding_menu_controller.cc',
'browser/ui/toolbar/encoding_menu_controller.h',
- 'browser/ui/toolbar/toolbar_model.cc',
'browser/ui/toolbar/toolbar_model.h',
+ 'browser/ui/toolbar/toolbar_model_impl.cc',
+ 'browser/ui/toolbar/toolbar_model_impl.h',
'browser/ui/toolbar/toolbar_model_delegate.h',
'browser/ui/toolbar/wrench_menu_model.cc',
'browser/ui/toolbar/wrench_menu_model.h',
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index a93b756..c454867 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1915,6 +1915,8 @@
'browser/ui/toolbar/back_forward_menu_model_unittest.cc',
'browser/ui/toolbar/encoding_menu_controller_unittest.cc',
'browser/ui/toolbar/toolbar_model_unittest.cc',
+ 'browser/ui/toolbar/test_toolbar_model.cc',
+ 'browser/ui/toolbar/test_toolbar_model.h',
'browser/ui/toolbar/wrench_menu_model_unittest.cc',
'browser/ui/views/accelerator_table_unittest.cc',
'browser/ui/views/accessibility/accessibility_event_router_views_unittest.cc',