summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorhbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-19 02:36:36 +0000
committerhbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-19 02:36:36 +0000
commitbac8784c4127d82a9d4964c93c59249af7668ab4 (patch)
tree1ddd39486c32e52342502028ec1bcc29b8733d33 /chrome
parentf93fe78db9c83619fd55aeccdade102915404c28 (diff)
downloadchromium_src-bac8784c4127d82a9d4964c93c59249af7668ab4.zip
chromium_src-bac8784c4127d82a9d4964c93c59249af7668ab4.tar.gz
chromium_src-bac8784c4127d82a9d4964c93c59249af7668ab4.tar.bz2
Changes line endings from CRLF to LF and add svn:eol-style to LF.
No code changes. This change just changes the CRLF line endings found by your change to make your change work on Mac and Linux trybots. Review URL: http://codereview.chromium.org/21445 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10001 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/renderer_host/mock_render_process_host.cc128
-rw-r--r--chrome/browser/views/about_ipc_dialog.cc876
-rw-r--r--chrome/views/label_unittest.cc844
3 files changed, 924 insertions, 924 deletions
diff --git a/chrome/browser/renderer_host/mock_render_process_host.cc b/chrome/browser/renderer_host/mock_render_process_host.cc
index c1c9ae9..c345b59 100644
--- a/chrome/browser/renderer_host/mock_render_process_host.cc
+++ b/chrome/browser/renderer_host/mock_render_process_host.cc
@@ -1,64 +1,64 @@
-// Copyright (c) 2009 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/renderer_host/mock_render_process_host.h"
-
-MockRenderProcessHost::MockRenderProcessHost(Profile* profile)
- : RenderProcessHost(profile) {
-}
-
-MockRenderProcessHost::~MockRenderProcessHost() {
-}
-
-bool MockRenderProcessHost::Init() {
- return true;
-}
-
-int MockRenderProcessHost::GetNextRoutingID() {
- static int prev_routing_id = 0;
- return ++prev_routing_id;
-}
-
-void MockRenderProcessHost::CancelResourceRequests(int render_widget_id) {
-}
-
-void MockRenderProcessHost::CrossSiteClosePageACK(
- int new_render_process_host_id,
- int new_request_id) {
-}
-
-bool MockRenderProcessHost::WaitForPaintMsg(int render_widget_id,
- const base::TimeDelta& max_delay,
- IPC::Message* msg) {
- return false;
-}
-
-void MockRenderProcessHost::ReceivedBadMessage(uint16 msg_type) {
-}
-
-void MockRenderProcessHost::WidgetRestored() {
-}
-
-void MockRenderProcessHost::WidgetHidden() {
-}
-
-void MockRenderProcessHost::AddWord(const std::wstring& word) {
-}
-
-bool MockRenderProcessHost::FastShutdownIfPossible() {
- return false;
-}
-
-bool MockRenderProcessHost::Send(IPC::Message* msg) {
- // Save the message in the sink.
- sink_.OnMessageReceived(*msg);
- delete msg;
- return true;
-}
-
-void MockRenderProcessHost::OnMessageReceived(const IPC::Message& msg) {
-}
-
-void MockRenderProcessHost::OnChannelConnected(int32 peer_pid) {
-}
+// Copyright (c) 2009 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/renderer_host/mock_render_process_host.h"
+
+MockRenderProcessHost::MockRenderProcessHost(Profile* profile)
+ : RenderProcessHost(profile) {
+}
+
+MockRenderProcessHost::~MockRenderProcessHost() {
+}
+
+bool MockRenderProcessHost::Init() {
+ return true;
+}
+
+int MockRenderProcessHost::GetNextRoutingID() {
+ static int prev_routing_id = 0;
+ return ++prev_routing_id;
+}
+
+void MockRenderProcessHost::CancelResourceRequests(int render_widget_id) {
+}
+
+void MockRenderProcessHost::CrossSiteClosePageACK(
+ int new_render_process_host_id,
+ int new_request_id) {
+}
+
+bool MockRenderProcessHost::WaitForPaintMsg(int render_widget_id,
+ const base::TimeDelta& max_delay,
+ IPC::Message* msg) {
+ return false;
+}
+
+void MockRenderProcessHost::ReceivedBadMessage(uint16 msg_type) {
+}
+
+void MockRenderProcessHost::WidgetRestored() {
+}
+
+void MockRenderProcessHost::WidgetHidden() {
+}
+
+void MockRenderProcessHost::AddWord(const std::wstring& word) {
+}
+
+bool MockRenderProcessHost::FastShutdownIfPossible() {
+ return false;
+}
+
+bool MockRenderProcessHost::Send(IPC::Message* msg) {
+ // Save the message in the sink.
+ sink_.OnMessageReceived(*msg);
+ delete msg;
+ return true;
+}
+
+void MockRenderProcessHost::OnMessageReceived(const IPC::Message& msg) {
+}
+
+void MockRenderProcessHost::OnChannelConnected(int32 peer_pid) {
+}
diff --git a/chrome/browser/views/about_ipc_dialog.cc b/chrome/browser/views/about_ipc_dialog.cc
index 5b266a9..6c60840 100644
--- a/chrome/browser/views/about_ipc_dialog.cc
+++ b/chrome/browser/views/about_ipc_dialog.cc
@@ -1,439 +1,439 @@
-// Copyright (c) 2009 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.
-
-// Need to include this before any other file because it defines
-// IPC_MESSAGE_LOG_ENABLED. We need to use it to define
-// IPC_MESSAGE_MACROS_LOG_ENABLED so render_messages.h will generate the
-// ViewMsgLog et al. functions.
-#include "chrome/common/ipc_message.h"
-
-#ifdef IPC_MESSAGE_LOG_ENABLED
-#define IPC_MESSAGE_MACROS_LOG_ENABLED
-
-#include "chrome/browser/views/about_ipc_dialog.h"
-
-#include <set>
-
-#include "base/string_util.h"
-#include "base/thread.h"
-#include "base/time.h"
-#include "chrome/app/chrome_dll_resource.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/views/standard_layout.h"
-#include "chrome/common/chrome_constants.h"
-#include "chrome/common/plugin_messages.h"
-#include "chrome/common/render_messages.h"
-#include "chrome/views/grid_layout.h"
-#include "chrome/views/text_button.h"
-#include "chrome/views/window.h"
-#include "net/url_request/url_request.h"
-#include "net/url_request/url_request_job.h"
-#include "net/url_request/url_request_job_tracker.h"
-#include "chrome/views/hwnd_view.h"
-#include "chrome/views/root_view.h"
-
-namespace {
-
-// We don't localize this UI since this is a developer-only feature.
-const wchar_t kStartTrackingLabel[] = L"Start tracking";
-const wchar_t kStopTrackingLabel[] = L"Stop tracking";
-const wchar_t kClearLabel[] = L"Clear";
-const wchar_t kFilterLabel[] = L"Filter...";
-
-enum {
- kTimeColumn = 0,
- kChannelColumn,
- kMessageColumn,
- kFlagsColumn,
- kDispatchColumn,
- kProcessColumn,
- kParamsColumn,
-};
-
-// This class registers the browser IPC logger functions with IPC::Logging.
-class RegisterLoggerFuncs {
- public:
- RegisterLoggerFuncs() {
- IPC::Logging::SetLoggerFunctions(g_log_function_mapping);
- }
-};
-
-RegisterLoggerFuncs g_register_logger_funcs;
-
-// The singleton dialog box. This is non-NULL when a dialog is active so we
-// know not to create a new one.
-AboutIPCDialog* active_dialog = NULL;
-
-std::set<int> disabled_messages;
-
-// Settings dialog -------------------------------------------------------------
-
-bool init_done = false;
-HWND settings_dialog = NULL;
-
-// Settings lists.
-struct Settings {
- CListViewCtrl* view;
- CListViewCtrl* view_host;
- CListViewCtrl* plugin;
- CListViewCtrl* plugin_host;
- CListViewCtrl* npobject;
- CListViewCtrl* plugin_process;
- CListViewCtrl* plugin_process_host;
-} settings_views = { NULL, NULL, NULL, NULL, NULL, NULL, NULL };
-
-void CreateColumn(uint16 start, uint16 end, HWND hwnd,
- CListViewCtrl** control) {
- DCHECK(*control == NULL);
- *control = new CListViewCtrl(hwnd);
- CListViewCtrl* control_ptr = *control;
- control_ptr->SetViewType(LVS_REPORT);
- control_ptr->SetExtendedListViewStyle(LVS_EX_CHECKBOXES);
- control_ptr->ModifyStyle(0, LVS_SORTASCENDING | LVS_NOCOLUMNHEADER);
- control_ptr->InsertColumn(0, L"id", LVCFMT_LEFT, 230);
-
- for (uint16 i = start; i < end; i++) {
- std::wstring name;
- IPC::Logging::GetMessageText(i, &name, NULL, NULL);
-
- int index = control_ptr->InsertItem(
- LVIF_TEXT | LVIF_PARAM, 0, name.c_str(), 0, 0, 0, i);
-
- control_ptr->SetItemText(index, 0, name.c_str());
-
- if (disabled_messages.find(i) == disabled_messages.end())
- control_ptr->SetCheckState(index, TRUE);
- }
-}
-
-void OnCheck(int id, bool checked) {
- if (!init_done)
- return;
-
- if (checked)
- disabled_messages.erase(id);
- else
- disabled_messages.insert(id);
-}
-
-
-void CheckButtons(CListViewCtrl* control, bool check) {
- int count = control->GetItemCount();
- for (int i = 0; i < count; ++i)
- control->SetCheckState(i, check);
-}
-
-void InitDialog(HWND hwnd) {
- CreateColumn(ViewStart, ViewEnd, ::GetDlgItem(hwnd, IDC_View),
- &settings_views.view);
- CreateColumn(ViewHostStart, ViewHostEnd, ::GetDlgItem(hwnd, IDC_ViewHost),
- &settings_views.view_host);
- CreateColumn(PluginStart, PluginEnd, ::GetDlgItem(hwnd, IDC_Plugin),
- &settings_views.plugin);
- CreateColumn(PluginHostStart, PluginHostEnd,
- ::GetDlgItem(hwnd, IDC_PluginHost),
- &settings_views.plugin_host);
- CreateColumn(NPObjectStart, NPObjectEnd, ::GetDlgItem(hwnd, IDC_NPObject),
- &settings_views.npobject);
- CreateColumn(PluginProcessStart, PluginProcessEnd,
- ::GetDlgItem(hwnd, IDC_PluginProcess),
- &settings_views.plugin_process);
- CreateColumn(PluginProcessHostStart, PluginProcessHostEnd,
- ::GetDlgItem(hwnd, IDC_PluginProcessHost),
- &settings_views.plugin_process_host);
- init_done = true;
-}
-
-void CloseDialog() {
- delete settings_views.view;
- delete settings_views.view_host;
- delete settings_views.plugin_host;
- delete settings_views.npobject;
- delete settings_views.plugin_process;
- delete settings_views.plugin_process_host;
- settings_views.view = NULL;
- settings_views.view_host = NULL;
- settings_views.plugin = NULL;
- settings_views.plugin_host = NULL;
- settings_views.npobject = NULL;
- settings_views.plugin_process = NULL;
- settings_views.plugin_process_host = NULL;
-
- init_done = false;
-
- ::DestroyWindow(settings_dialog);
- settings_dialog = NULL;
-
- /* The old version of this code stored the last settings in the preferences.
- But with this dialog, there currently isn't an easy way to get the profile
- to asave in the preferences.
- Profile* current_profile = profile();
- if (!current_profile)
- return;
- PrefService* prefs = current_profile->GetPrefs();
- if (!prefs->IsPrefRegistered(prefs::kIpcDisabledMessages))
- return;
- ListValue* list = prefs->GetMutableList(prefs::kIpcDisabledMessages);
- list->Clear();
- for (std::set<int>::const_iterator itr = disabled_messages_.begin();
- itr != disabled_messages_.end();
- ++itr) {
- list->Append(Value::CreateIntegerValue(*itr));
- }
- */
-}
-
-void OnButtonClick(int id) {
- switch(id) {
- case IDC_ViewAll:
- CheckButtons(settings_views.view, true);
- break;
- case IDC_ViewNone:
- CheckButtons(settings_views.view, false);
- break;
- case IDC_ViewHostAll:
- CheckButtons(settings_views.view_host, true);
- break;
- case IDC_ViewHostNone:
- CheckButtons(settings_views.view_host, false);
- break;
- case IDC_PluginAll:
- CheckButtons(settings_views.plugin, true);
- break;
- case IDC_PluginNone:
- CheckButtons(settings_views.plugin, false);
- break;
- case IDC_PluginHostAll:
- CheckButtons(settings_views.plugin_host, true);
- break;
- case IDC_PluginHostNone:
- CheckButtons(settings_views.plugin_host, false);
- break;
- case IDC_NPObjectAll:
- CheckButtons(settings_views.npobject, true);
- break;
- case IDC_NPObjectNone:
- CheckButtons(settings_views.npobject, false);
- break;
- }
-}
-
-INT_PTR CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
- switch (msg) {
- case WM_INITDIALOG:
- InitDialog(hwnd);
- return FALSE; // Don't set keyboard focus.
- case WM_SYSCOMMAND:
- if (wparam == SC_CLOSE) {
- CloseDialog();
- return FALSE;
- }
- break;
- case WM_NOTIFY: {
- NMLISTVIEW* info = reinterpret_cast<NM_LISTVIEW*>(lparam);
- if ((wparam == IDC_View || wparam == IDC_ViewHost || wparam == IDC_Plugin ||
- wparam == IDC_PluginHost || wparam == IDC_NPObject ||
- wparam == IDC_PluginProcess || wparam == IDC_PluginProcessHost) &&
- info->hdr.code == LVN_ITEMCHANGED) {
- if (info->uChanged & LVIF_STATE) {
- bool checked = (info->uNewState >> 12) == 2;
- OnCheck(static_cast<int>(info->lParam), checked);
- }
- return FALSE;
- }
- break;
- }
- case WM_COMMAND:
- if (HIWORD(wparam) == BN_CLICKED)
- OnButtonClick(LOWORD(wparam));
- break;
- }
- return FALSE;
-}
-
-void RunSettingsDialog(HWND parent) {
- if (settings_dialog)
- return;
- HINSTANCE module_handle = GetModuleHandle(chrome::kBrowserResourcesDll);
- settings_dialog = CreateDialog(module_handle,
- MAKEINTRESOURCE(IDD_IPC_SETTINGS),
- NULL,
- &DialogProc);
- ::ShowWindow(settings_dialog, SW_SHOW);
-}
-
-} // namespace
-
-// AboutIPCDialog --------------------------------------------------------------
-
-AboutIPCDialog::AboutIPCDialog()
- : track_toggle_(NULL),
- clear_button_(NULL),
- filter_button_(NULL),
- table_(NULL),
- tracking_(false) {
- SetupControls();
- IPC::Logging::current()->SetConsumer(this);
-}
-
-AboutIPCDialog::~AboutIPCDialog() {
- active_dialog = NULL;
- IPC::Logging::current()->SetConsumer(NULL);
-}
-
-// static
-void AboutIPCDialog::RunDialog() {
- if (!active_dialog) {
- active_dialog = new AboutIPCDialog;
- views::Window::CreateChromeWindow(NULL, gfx::Rect(), active_dialog)->Show();
- } else {
- // TOOD(brettw) it would be nice to focus the existing window.
- }
-}
-
-void AboutIPCDialog::SetupControls() {
- views::GridLayout* layout = CreatePanelGridLayout(this);
- SetLayoutManager(layout);
-
- track_toggle_ = new views::TextButton(kStartTrackingLabel);
- track_toggle_->SetListener(this, 1);
- clear_button_ = new views::TextButton(kClearLabel);
- clear_button_->SetListener(this, 2);
- filter_button_ = new views::TextButton(kFilterLabel);
- filter_button_->SetListener(this, 3);
-
- table_ = new views::HWNDView();
-
- static const int first_column_set = 1;
- views::ColumnSet* column_set = layout->AddColumnSet(first_column_set);
- column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER,
- 33.33f, views::GridLayout::FIXED, 0, 0);
- column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER,
- 33.33f, views::GridLayout::FIXED, 0, 0);
- column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER,
- 33.33f, views::GridLayout::FIXED, 0, 0);
-
- static const int table_column_set = 2;
- column_set = layout->AddColumnSet(table_column_set);
- column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
- 100.0f, views::GridLayout::FIXED, 0, 0);
-
- layout->StartRow(0, first_column_set);
- layout->AddView(track_toggle_);
- layout->AddView(clear_button_);
- layout->AddView(filter_button_);
- layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
- layout->StartRow(1.0f, table_column_set);
- layout->AddView(table_);
-}
-
-gfx::Size AboutIPCDialog::GetPreferredSize() {
- return gfx::Size(800, 400);
-}
-
-views::View* AboutIPCDialog::GetContentsView() {
- return this;
-}
-
-int AboutIPCDialog::GetDialogButtons() const {
- // Don't want OK or Cancel.
- return 0;
-}
-
-std::wstring AboutIPCDialog::GetWindowTitle() const {
- return L"about:ipc";
-}
-
-void AboutIPCDialog::Layout() {
- if (!message_list_.m_hWnd) {
- HWND parent_window = GetRootView()->GetWidget()->GetHWND();
-
- CRect rect(0, 0, 10, 10);
- HWND list_hwnd = message_list_.Create(parent_window,
- rect, NULL, WS_CHILD | WS_VISIBLE | LVS_SORTASCENDING);
- message_list_.SetViewType(LVS_REPORT);
- message_list_.SetExtendedListViewStyle(LVS_EX_FULLROWSELECT);
-
- int column_index = 0;
- message_list_.InsertColumn(kTimeColumn, L"time", LVCFMT_LEFT, 80);
- message_list_.InsertColumn(kChannelColumn, L"channel", LVCFMT_LEFT, 110);
- message_list_.InsertColumn(kMessageColumn, L"message", LVCFMT_LEFT, 240);
- message_list_.InsertColumn(kFlagsColumn, L"flags", LVCFMT_LEFT, 50);
- message_list_.InsertColumn(kDispatchColumn, L"dispatch (ms)", LVCFMT_RIGHT,
- 80);
- message_list_.InsertColumn(kProcessColumn, L"process (ms)", LVCFMT_RIGHT,
- 80);
- message_list_.InsertColumn(kParamsColumn, L"parameters", LVCFMT_LEFT, 500);
-
- table_->Attach(list_hwnd);
- }
-
- View::Layout();
-}
-
-void AboutIPCDialog::Log(const IPC::LogData& data) {
- if (disabled_messages.find(data.type) != disabled_messages.end())
- return; // Message type is filtered out.
-
- base::Time sent = base::Time::FromInternalValue(data.sent);
- base::Time::Exploded exploded;
- sent.LocalExplode(&exploded);
- if (exploded.hour > 12)
- exploded.hour -= 12;
-
- std::wstring sent_str = StringPrintf(L"%02d:%02d:%02d.%03d",
- exploded.hour, exploded.minute, exploded.second, exploded.millisecond);
-
- int count = message_list_.GetItemCount();
- int index = message_list_.InsertItem(count, sent_str.c_str());
-
- message_list_.SetItemText(index, kTimeColumn, sent_str.c_str());
- message_list_.SetItemText(index, kChannelColumn, data.channel.c_str());
-
- std::wstring message_name;
- IPC::Logging::GetMessageText(data.type, &message_name, NULL, NULL);
- message_list_.SetItemText(index, kMessageColumn, message_name.c_str());
- message_list_.SetItemText(index, kFlagsColumn, data.flags.c_str());
-
- int64 time_to_send = (base::Time::FromInternalValue(data.receive) -
- sent).InMilliseconds();
- // time can go backwards by a few ms (see Time), don't show that.
- time_to_send = std::max(static_cast<int>(time_to_send), 0);
- std::wstring temp = StringPrintf(L"%d", time_to_send);
- message_list_.SetItemText(index, kDispatchColumn, temp.c_str());
-
- int64 time_to_process = (base::Time::FromInternalValue(data.dispatch) -
- base::Time::FromInternalValue(data.receive)).InMilliseconds();
- time_to_process = std::max(static_cast<int>(time_to_process), 0);
- temp = StringPrintf(L"%d", time_to_process);
- message_list_.SetItemText(index, kProcessColumn, temp.c_str());
-
- message_list_.SetItemText(index, kParamsColumn, data.params.c_str());
- message_list_.EnsureVisible(index, FALSE);
-}
-
-bool AboutIPCDialog::CanResize() const {
- return true;
-}
-
-void AboutIPCDialog::ButtonPressed(views::BaseButton* button) {
- if (button == track_toggle_) {
- if (tracking_) {
- track_toggle_->SetText(kStartTrackingLabel);
- tracking_ = false;
- IPC::Logging::current()->Disable();
- } else {
- track_toggle_->SetText(kStopTrackingLabel);
- tracking_ = true;
- IPC::Logging::current()->Enable();
- }
- track_toggle_->SchedulePaint();
- } else if (button == clear_button_) {
- message_list_.DeleteAllItems();
- } else if (button == filter_button_) {
- RunSettingsDialog(GetRootView()->GetWidget()->GetHWND());
- }
-}
-
+// Copyright (c) 2009 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.
+
+// Need to include this before any other file because it defines
+// IPC_MESSAGE_LOG_ENABLED. We need to use it to define
+// IPC_MESSAGE_MACROS_LOG_ENABLED so render_messages.h will generate the
+// ViewMsgLog et al. functions.
+#include "chrome/common/ipc_message.h"
+
+#ifdef IPC_MESSAGE_LOG_ENABLED
+#define IPC_MESSAGE_MACROS_LOG_ENABLED
+
+#include "chrome/browser/views/about_ipc_dialog.h"
+
+#include <set>
+
+#include "base/string_util.h"
+#include "base/thread.h"
+#include "base/time.h"
+#include "chrome/app/chrome_dll_resource.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/views/standard_layout.h"
+#include "chrome/common/chrome_constants.h"
+#include "chrome/common/plugin_messages.h"
+#include "chrome/common/render_messages.h"
+#include "chrome/views/grid_layout.h"
+#include "chrome/views/text_button.h"
+#include "chrome/views/window.h"
+#include "net/url_request/url_request.h"
+#include "net/url_request/url_request_job.h"
+#include "net/url_request/url_request_job_tracker.h"
+#include "chrome/views/hwnd_view.h"
+#include "chrome/views/root_view.h"
+
+namespace {
+
+// We don't localize this UI since this is a developer-only feature.
+const wchar_t kStartTrackingLabel[] = L"Start tracking";
+const wchar_t kStopTrackingLabel[] = L"Stop tracking";
+const wchar_t kClearLabel[] = L"Clear";
+const wchar_t kFilterLabel[] = L"Filter...";
+
+enum {
+ kTimeColumn = 0,
+ kChannelColumn,
+ kMessageColumn,
+ kFlagsColumn,
+ kDispatchColumn,
+ kProcessColumn,
+ kParamsColumn,
+};
+
+// This class registers the browser IPC logger functions with IPC::Logging.
+class RegisterLoggerFuncs {
+ public:
+ RegisterLoggerFuncs() {
+ IPC::Logging::SetLoggerFunctions(g_log_function_mapping);
+ }
+};
+
+RegisterLoggerFuncs g_register_logger_funcs;
+
+// The singleton dialog box. This is non-NULL when a dialog is active so we
+// know not to create a new one.
+AboutIPCDialog* active_dialog = NULL;
+
+std::set<int> disabled_messages;
+
+// Settings dialog -------------------------------------------------------------
+
+bool init_done = false;
+HWND settings_dialog = NULL;
+
+// Settings lists.
+struct Settings {
+ CListViewCtrl* view;
+ CListViewCtrl* view_host;
+ CListViewCtrl* plugin;
+ CListViewCtrl* plugin_host;
+ CListViewCtrl* npobject;
+ CListViewCtrl* plugin_process;
+ CListViewCtrl* plugin_process_host;
+} settings_views = { NULL, NULL, NULL, NULL, NULL, NULL, NULL };
+
+void CreateColumn(uint16 start, uint16 end, HWND hwnd,
+ CListViewCtrl** control) {
+ DCHECK(*control == NULL);
+ *control = new CListViewCtrl(hwnd);
+ CListViewCtrl* control_ptr = *control;
+ control_ptr->SetViewType(LVS_REPORT);
+ control_ptr->SetExtendedListViewStyle(LVS_EX_CHECKBOXES);
+ control_ptr->ModifyStyle(0, LVS_SORTASCENDING | LVS_NOCOLUMNHEADER);
+ control_ptr->InsertColumn(0, L"id", LVCFMT_LEFT, 230);
+
+ for (uint16 i = start; i < end; i++) {
+ std::wstring name;
+ IPC::Logging::GetMessageText(i, &name, NULL, NULL);
+
+ int index = control_ptr->InsertItem(
+ LVIF_TEXT | LVIF_PARAM, 0, name.c_str(), 0, 0, 0, i);
+
+ control_ptr->SetItemText(index, 0, name.c_str());
+
+ if (disabled_messages.find(i) == disabled_messages.end())
+ control_ptr->SetCheckState(index, TRUE);
+ }
+}
+
+void OnCheck(int id, bool checked) {
+ if (!init_done)
+ return;
+
+ if (checked)
+ disabled_messages.erase(id);
+ else
+ disabled_messages.insert(id);
+}
+
+
+void CheckButtons(CListViewCtrl* control, bool check) {
+ int count = control->GetItemCount();
+ for (int i = 0; i < count; ++i)
+ control->SetCheckState(i, check);
+}
+
+void InitDialog(HWND hwnd) {
+ CreateColumn(ViewStart, ViewEnd, ::GetDlgItem(hwnd, IDC_View),
+ &settings_views.view);
+ CreateColumn(ViewHostStart, ViewHostEnd, ::GetDlgItem(hwnd, IDC_ViewHost),
+ &settings_views.view_host);
+ CreateColumn(PluginStart, PluginEnd, ::GetDlgItem(hwnd, IDC_Plugin),
+ &settings_views.plugin);
+ CreateColumn(PluginHostStart, PluginHostEnd,
+ ::GetDlgItem(hwnd, IDC_PluginHost),
+ &settings_views.plugin_host);
+ CreateColumn(NPObjectStart, NPObjectEnd, ::GetDlgItem(hwnd, IDC_NPObject),
+ &settings_views.npobject);
+ CreateColumn(PluginProcessStart, PluginProcessEnd,
+ ::GetDlgItem(hwnd, IDC_PluginProcess),
+ &settings_views.plugin_process);
+ CreateColumn(PluginProcessHostStart, PluginProcessHostEnd,
+ ::GetDlgItem(hwnd, IDC_PluginProcessHost),
+ &settings_views.plugin_process_host);
+ init_done = true;
+}
+
+void CloseDialog() {
+ delete settings_views.view;
+ delete settings_views.view_host;
+ delete settings_views.plugin_host;
+ delete settings_views.npobject;
+ delete settings_views.plugin_process;
+ delete settings_views.plugin_process_host;
+ settings_views.view = NULL;
+ settings_views.view_host = NULL;
+ settings_views.plugin = NULL;
+ settings_views.plugin_host = NULL;
+ settings_views.npobject = NULL;
+ settings_views.plugin_process = NULL;
+ settings_views.plugin_process_host = NULL;
+
+ init_done = false;
+
+ ::DestroyWindow(settings_dialog);
+ settings_dialog = NULL;
+
+ /* The old version of this code stored the last settings in the preferences.
+ But with this dialog, there currently isn't an easy way to get the profile
+ to asave in the preferences.
+ Profile* current_profile = profile();
+ if (!current_profile)
+ return;
+ PrefService* prefs = current_profile->GetPrefs();
+ if (!prefs->IsPrefRegistered(prefs::kIpcDisabledMessages))
+ return;
+ ListValue* list = prefs->GetMutableList(prefs::kIpcDisabledMessages);
+ list->Clear();
+ for (std::set<int>::const_iterator itr = disabled_messages_.begin();
+ itr != disabled_messages_.end();
+ ++itr) {
+ list->Append(Value::CreateIntegerValue(*itr));
+ }
+ */
+}
+
+void OnButtonClick(int id) {
+ switch(id) {
+ case IDC_ViewAll:
+ CheckButtons(settings_views.view, true);
+ break;
+ case IDC_ViewNone:
+ CheckButtons(settings_views.view, false);
+ break;
+ case IDC_ViewHostAll:
+ CheckButtons(settings_views.view_host, true);
+ break;
+ case IDC_ViewHostNone:
+ CheckButtons(settings_views.view_host, false);
+ break;
+ case IDC_PluginAll:
+ CheckButtons(settings_views.plugin, true);
+ break;
+ case IDC_PluginNone:
+ CheckButtons(settings_views.plugin, false);
+ break;
+ case IDC_PluginHostAll:
+ CheckButtons(settings_views.plugin_host, true);
+ break;
+ case IDC_PluginHostNone:
+ CheckButtons(settings_views.plugin_host, false);
+ break;
+ case IDC_NPObjectAll:
+ CheckButtons(settings_views.npobject, true);
+ break;
+ case IDC_NPObjectNone:
+ CheckButtons(settings_views.npobject, false);
+ break;
+ }
+}
+
+INT_PTR CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
+ switch (msg) {
+ case WM_INITDIALOG:
+ InitDialog(hwnd);
+ return FALSE; // Don't set keyboard focus.
+ case WM_SYSCOMMAND:
+ if (wparam == SC_CLOSE) {
+ CloseDialog();
+ return FALSE;
+ }
+ break;
+ case WM_NOTIFY: {
+ NMLISTVIEW* info = reinterpret_cast<NM_LISTVIEW*>(lparam);
+ if ((wparam == IDC_View || wparam == IDC_ViewHost || wparam == IDC_Plugin ||
+ wparam == IDC_PluginHost || wparam == IDC_NPObject ||
+ wparam == IDC_PluginProcess || wparam == IDC_PluginProcessHost) &&
+ info->hdr.code == LVN_ITEMCHANGED) {
+ if (info->uChanged & LVIF_STATE) {
+ bool checked = (info->uNewState >> 12) == 2;
+ OnCheck(static_cast<int>(info->lParam), checked);
+ }
+ return FALSE;
+ }
+ break;
+ }
+ case WM_COMMAND:
+ if (HIWORD(wparam) == BN_CLICKED)
+ OnButtonClick(LOWORD(wparam));
+ break;
+ }
+ return FALSE;
+}
+
+void RunSettingsDialog(HWND parent) {
+ if (settings_dialog)
+ return;
+ HINSTANCE module_handle = GetModuleHandle(chrome::kBrowserResourcesDll);
+ settings_dialog = CreateDialog(module_handle,
+ MAKEINTRESOURCE(IDD_IPC_SETTINGS),
+ NULL,
+ &DialogProc);
+ ::ShowWindow(settings_dialog, SW_SHOW);
+}
+
+} // namespace
+
+// AboutIPCDialog --------------------------------------------------------------
+
+AboutIPCDialog::AboutIPCDialog()
+ : track_toggle_(NULL),
+ clear_button_(NULL),
+ filter_button_(NULL),
+ table_(NULL),
+ tracking_(false) {
+ SetupControls();
+ IPC::Logging::current()->SetConsumer(this);
+}
+
+AboutIPCDialog::~AboutIPCDialog() {
+ active_dialog = NULL;
+ IPC::Logging::current()->SetConsumer(NULL);
+}
+
+// static
+void AboutIPCDialog::RunDialog() {
+ if (!active_dialog) {
+ active_dialog = new AboutIPCDialog;
+ views::Window::CreateChromeWindow(NULL, gfx::Rect(), active_dialog)->Show();
+ } else {
+ // TOOD(brettw) it would be nice to focus the existing window.
+ }
+}
+
+void AboutIPCDialog::SetupControls() {
+ views::GridLayout* layout = CreatePanelGridLayout(this);
+ SetLayoutManager(layout);
+
+ track_toggle_ = new views::TextButton(kStartTrackingLabel);
+ track_toggle_->SetListener(this, 1);
+ clear_button_ = new views::TextButton(kClearLabel);
+ clear_button_->SetListener(this, 2);
+ filter_button_ = new views::TextButton(kFilterLabel);
+ filter_button_->SetListener(this, 3);
+
+ table_ = new views::HWNDView();
+
+ static const int first_column_set = 1;
+ views::ColumnSet* column_set = layout->AddColumnSet(first_column_set);
+ column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER,
+ 33.33f, views::GridLayout::FIXED, 0, 0);
+ column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER,
+ 33.33f, views::GridLayout::FIXED, 0, 0);
+ column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER,
+ 33.33f, views::GridLayout::FIXED, 0, 0);
+
+ static const int table_column_set = 2;
+ column_set = layout->AddColumnSet(table_column_set);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 100.0f, views::GridLayout::FIXED, 0, 0);
+
+ layout->StartRow(0, first_column_set);
+ layout->AddView(track_toggle_);
+ layout->AddView(clear_button_);
+ layout->AddView(filter_button_);
+ layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
+ layout->StartRow(1.0f, table_column_set);
+ layout->AddView(table_);
+}
+
+gfx::Size AboutIPCDialog::GetPreferredSize() {
+ return gfx::Size(800, 400);
+}
+
+views::View* AboutIPCDialog::GetContentsView() {
+ return this;
+}
+
+int AboutIPCDialog::GetDialogButtons() const {
+ // Don't want OK or Cancel.
+ return 0;
+}
+
+std::wstring AboutIPCDialog::GetWindowTitle() const {
+ return L"about:ipc";
+}
+
+void AboutIPCDialog::Layout() {
+ if (!message_list_.m_hWnd) {
+ HWND parent_window = GetRootView()->GetWidget()->GetHWND();
+
+ CRect rect(0, 0, 10, 10);
+ HWND list_hwnd = message_list_.Create(parent_window,
+ rect, NULL, WS_CHILD | WS_VISIBLE | LVS_SORTASCENDING);
+ message_list_.SetViewType(LVS_REPORT);
+ message_list_.SetExtendedListViewStyle(LVS_EX_FULLROWSELECT);
+
+ int column_index = 0;
+ message_list_.InsertColumn(kTimeColumn, L"time", LVCFMT_LEFT, 80);
+ message_list_.InsertColumn(kChannelColumn, L"channel", LVCFMT_LEFT, 110);
+ message_list_.InsertColumn(kMessageColumn, L"message", LVCFMT_LEFT, 240);
+ message_list_.InsertColumn(kFlagsColumn, L"flags", LVCFMT_LEFT, 50);
+ message_list_.InsertColumn(kDispatchColumn, L"dispatch (ms)", LVCFMT_RIGHT,
+ 80);
+ message_list_.InsertColumn(kProcessColumn, L"process (ms)", LVCFMT_RIGHT,
+ 80);
+ message_list_.InsertColumn(kParamsColumn, L"parameters", LVCFMT_LEFT, 500);
+
+ table_->Attach(list_hwnd);
+ }
+
+ View::Layout();
+}
+
+void AboutIPCDialog::Log(const IPC::LogData& data) {
+ if (disabled_messages.find(data.type) != disabled_messages.end())
+ return; // Message type is filtered out.
+
+ base::Time sent = base::Time::FromInternalValue(data.sent);
+ base::Time::Exploded exploded;
+ sent.LocalExplode(&exploded);
+ if (exploded.hour > 12)
+ exploded.hour -= 12;
+
+ std::wstring sent_str = StringPrintf(L"%02d:%02d:%02d.%03d",
+ exploded.hour, exploded.minute, exploded.second, exploded.millisecond);
+
+ int count = message_list_.GetItemCount();
+ int index = message_list_.InsertItem(count, sent_str.c_str());
+
+ message_list_.SetItemText(index, kTimeColumn, sent_str.c_str());
+ message_list_.SetItemText(index, kChannelColumn, data.channel.c_str());
+
+ std::wstring message_name;
+ IPC::Logging::GetMessageText(data.type, &message_name, NULL, NULL);
+ message_list_.SetItemText(index, kMessageColumn, message_name.c_str());
+ message_list_.SetItemText(index, kFlagsColumn, data.flags.c_str());
+
+ int64 time_to_send = (base::Time::FromInternalValue(data.receive) -
+ sent).InMilliseconds();
+ // time can go backwards by a few ms (see Time), don't show that.
+ time_to_send = std::max(static_cast<int>(time_to_send), 0);
+ std::wstring temp = StringPrintf(L"%d", time_to_send);
+ message_list_.SetItemText(index, kDispatchColumn, temp.c_str());
+
+ int64 time_to_process = (base::Time::FromInternalValue(data.dispatch) -
+ base::Time::FromInternalValue(data.receive)).InMilliseconds();
+ time_to_process = std::max(static_cast<int>(time_to_process), 0);
+ temp = StringPrintf(L"%d", time_to_process);
+ message_list_.SetItemText(index, kProcessColumn, temp.c_str());
+
+ message_list_.SetItemText(index, kParamsColumn, data.params.c_str());
+ message_list_.EnsureVisible(index, FALSE);
+}
+
+bool AboutIPCDialog::CanResize() const {
+ return true;
+}
+
+void AboutIPCDialog::ButtonPressed(views::BaseButton* button) {
+ if (button == track_toggle_) {
+ if (tracking_) {
+ track_toggle_->SetText(kStartTrackingLabel);
+ tracking_ = false;
+ IPC::Logging::current()->Disable();
+ } else {
+ track_toggle_->SetText(kStopTrackingLabel);
+ tracking_ = true;
+ IPC::Logging::current()->Enable();
+ }
+ track_toggle_->SchedulePaint();
+ } else if (button == clear_button_) {
+ message_list_.DeleteAllItems();
+ } else if (button == filter_button_) {
+ RunSettingsDialog(GetRootView()->GetWidget()->GetHWND());
+ }
+}
+
#endif // IPC_MESSAGE_LOG_ENABLED \ No newline at end of file
diff --git a/chrome/views/label_unittest.cc b/chrome/views/label_unittest.cc
index aec1b9b..e1f80bb0 100644
--- a/chrome/views/label_unittest.cc
+++ b/chrome/views/label_unittest.cc
@@ -1,422 +1,422 @@
-// Copyright (c) 2006-2008 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 "base/string_util.h"
-#include "chrome/common/l10n_util.h"
-#include "chrome/views/border.h"
-#include "chrome/views/label.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace views {
-
-// All text sizing measurements (width and height) should be greater than this.
-const int kMinTextDimension = 4;
-
-TEST(LabelTest, FontProperty) {
- Label label;
- std::wstring font_name(L"courier");
- ChromeFont font = ChromeFont::CreateFont(font_name, 30);
- label.SetFont(font);
- ChromeFont font_used = label.GetFont();
- EXPECT_STREQ(font_name.c_str(), font_used.FontName().c_str());
- EXPECT_EQ(30, font_used.FontSize());
-}
-
-TEST(LabelTest, TextProperty) {
- Label label;
- std::wstring test_text(L"A random string.");
- label.SetText(test_text);
- EXPECT_STREQ(test_text.c_str(), label.GetText().c_str());
-}
-
-TEST(LabelTest, UrlProperty) {
- Label label;
- std::string my_url("http://www.orkut.com/some/Random/path");
- GURL url(my_url);
- label.SetURL(url);
- EXPECT_STREQ(my_url.c_str(), label.GetURL().spec().c_str());
- EXPECT_STREQ(UTF8ToWide(my_url).c_str(), label.GetText().c_str());
-}
-
-TEST(LabelTest, ColorProperty) {
- Label label;
- SkColor color = SkColorSetARGB(20, 40, 10, 5);
- label.SetColor(color);
- EXPECT_EQ(color, label.GetColor());
-}
-
-TEST(LabelTest, AlignmentProperty) {
- Label label;
- bool reverse_alignment =
- l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT;
-
- label.SetHorizontalAlignment(Label::ALIGN_RIGHT);
- EXPECT_EQ(
- reverse_alignment ? Label::ALIGN_LEFT : Label::ALIGN_RIGHT,
- label.GetHorizontalAlignment());
- label.SetHorizontalAlignment(Label::ALIGN_LEFT);
- EXPECT_EQ(
- reverse_alignment ? Label::ALIGN_RIGHT : Label::ALIGN_LEFT,
- label.GetHorizontalAlignment());
- label.SetHorizontalAlignment(Label::ALIGN_CENTER);
- EXPECT_EQ(Label::ALIGN_CENTER, label.GetHorizontalAlignment());
-}
-
-TEST(LabelTest, MultiLineProperty) {
- Label label;
- EXPECT_FALSE(label.IsMultiLine());
- label.SetMultiLine(true);
- EXPECT_TRUE(label.IsMultiLine());
- label.SetMultiLine(false);
- EXPECT_FALSE(label.IsMultiLine());
-}
-
-TEST(LabelTest, TooltipProperty) {
- Label label;
- std::wstring test_text(L"My cool string.");
- label.SetText(test_text);
-
- std::wstring tooltip;
- EXPECT_TRUE(label.GetTooltipText(0, 0, &tooltip));
- EXPECT_STREQ(test_text.c_str(), tooltip.c_str());
-
- std::wstring tooltip_text(L"The tooltip!");
- label.SetTooltipText(tooltip_text);
- EXPECT_TRUE(label.GetTooltipText(0, 0, &tooltip));
- EXPECT_STREQ(tooltip_text.c_str(), tooltip.c_str());
-
- std::wstring empty_text;
- label.SetTooltipText(empty_text);
- EXPECT_TRUE(label.GetTooltipText(0, 0, &tooltip));
- EXPECT_STREQ(test_text.c_str(), tooltip.c_str());
-
- // Make the label big enough to hold the text
- // and expect there to be no tooltip.
- label.SetBounds(0, 0, 1000, 40);
- EXPECT_FALSE(label.GetTooltipText(0, 0, &tooltip));
-
- // Verify that setting the tooltip still shows it.
- label.SetTooltipText(tooltip_text);
- EXPECT_TRUE(label.GetTooltipText(0, 0, &tooltip));
- EXPECT_STREQ(tooltip_text.c_str(), tooltip.c_str());
- // Clear out the tooltip.
- label.SetTooltipText(empty_text);
-
- // Shrink the bounds and the tooltip should come back.
- label.SetBounds(0, 0, 1, 1);
- EXPECT_TRUE(label.GetTooltipText(0, 0, &tooltip));
-
- // Make the label multiline and there is no tooltip again.
- label.SetMultiLine(true);
- EXPECT_FALSE(label.GetTooltipText(0, 0, &tooltip));
-
- // Verify that setting the tooltip still shows it.
- label.SetTooltipText(tooltip_text);
- EXPECT_TRUE(label.GetTooltipText(0, 0, &tooltip));
- EXPECT_STREQ(tooltip_text.c_str(), tooltip.c_str());
- // Clear out the tooltip.
- label.SetTooltipText(empty_text);
-}
-
-TEST(LabelTest, Accessibility) {
- Label label;
- std::wstring test_text(L"My special text.");
- label.SetText(test_text);
-
- VARIANT role;
- ::VariantInit(&role);
- EXPECT_TRUE(label.GetAccessibleRole(&role));
- EXPECT_EQ(VT_I4, role.vt);
- EXPECT_EQ(ROLE_SYSTEM_TEXT, role.lVal);
-
- std::wstring name;
- EXPECT_TRUE(label.GetAccessibleName(&name));
- EXPECT_STREQ(test_text.c_str(), name.c_str());
-
- VARIANT state;
- ::VariantInit(&state);
- state.vt = VT_I4;
- state.lVal = 0;
- EXPECT_TRUE(label.GetAccessibleState(&state));
- EXPECT_EQ(VT_I4, state.vt);
- EXPECT_EQ(STATE_SYSTEM_READONLY, state.lVal);
-}
-
-TEST(LabelTest, SingleLineSizing) {
- Label label;
- std::wstring test_text(L"A not so random string in one line.");
- label.SetText(test_text);
-
- // GetPreferredSize
- gfx::Size required_size = label.GetPreferredSize();
- EXPECT_GT(required_size.height(), kMinTextDimension);
- EXPECT_GT(required_size.width(), kMinTextDimension);
-
- // Test everything with borders.
- gfx::Insets border(10, 20, 30, 40);
- label.set_border(Border::CreateEmptyBorder(border.top(),
- border.left(),
- border.bottom(),
- border.right()));
-
- // GetPreferredSize and borders.
- label.SetBounds(0, 0, 0, 0);
- gfx::Size required_size_with_border = label.GetPreferredSize();
- EXPECT_EQ(required_size_with_border.height(),
- required_size.height() + border.height());
- EXPECT_EQ(required_size_with_border.width(),
- required_size.width() + border.width());
-}
-
-TEST(LabelTest, MultiLineSizing) {
- Label label;
- std::wstring test_text(L"A random string\nwith multiple lines\nand returns!");
- label.SetText(test_text);
- label.SetMultiLine(true);
-
- // GetPreferredSize
- gfx::Size required_size = label.GetPreferredSize();
- EXPECT_GT(required_size.height(), kMinTextDimension);
- EXPECT_GT(required_size.width(), kMinTextDimension);
-
- // SizeToFit with unlimited width.
- label.SizeToFit(0);
- int required_width = label.GetLocalBounds(true).width();
- EXPECT_GT(required_width, kMinTextDimension);
-
- // SizeToFit with limited width.
- label.SizeToFit(required_width - 1);
- int constrained_width = label.GetLocalBounds(true).width();
- EXPECT_LT(constrained_width, required_width);
- EXPECT_GT(constrained_width, kMinTextDimension);
-
- // Change the width back to the desire width.
- label.SizeToFit(required_width);
- EXPECT_EQ(required_width, label.GetLocalBounds(true).width());
-
- // General tests for GetHeightForWidth.
- int required_height = label.GetHeightForWidth(required_width);
- EXPECT_GT(required_height, kMinTextDimension);
- int height_for_constrained_width = label.GetHeightForWidth(constrained_width);
- EXPECT_GT(height_for_constrained_width, required_height);
- // Using the constrained width or the required_width - 1 should give the
- // same result for the height because the constrainted width is the tight
- // width when given "required_width - 1" as the max width.
- EXPECT_EQ(height_for_constrained_width,
- label.GetHeightForWidth(required_width - 1));
-
- // Test everything with borders.
- gfx::Insets border(10, 20, 30, 40);
- label.set_border(Border::CreateEmptyBorder(border.top(),
- border.left(),
- border.bottom(),
- border.right()));
-
- // SizeToFit and borders.
- label.SizeToFit(0);
- int required_width_with_border = label.GetLocalBounds(true).width();
- EXPECT_EQ(required_width_with_border, required_width + border.width());
-
- // GetHeightForWidth and borders.
- int required_height_with_border =
- label.GetHeightForWidth(required_width_with_border);
- EXPECT_EQ(required_height_with_border, required_height + border.height());
-
- // Test that the border width is subtracted before doing the height
- // calculation. If it is, then the height will grow when width
- // is shrunk.
- int height1 = label.GetHeightForWidth(required_width_with_border - 1);
- EXPECT_GT(height1, required_height_with_border);
- EXPECT_EQ(height1, height_for_constrained_width + border.height());
-
- // GetPreferredSize and borders.
- label.SetBounds(0, 0, 0, 0);
- gfx::Size required_size_with_border = label.GetPreferredSize();
- EXPECT_EQ(required_size_with_border.height(),
- required_size.height() + border.height());
- EXPECT_EQ(required_size_with_border.width(),
- required_size.width() + border.width());
-}
-
-TEST(LabelTest, DrawSingleLineString) {
- Label label;
-
- // Turn off mirroring so that we don't need to figure out if
- // align right really means align left.
- label.EnableUIMirroringForRTLLanguages(false);
-
- std::wstring test_text(L"Here's a string with no returns.");
- label.SetText(test_text);
- gfx::Size required_size(label.GetPreferredSize());
- gfx::Size extra(22, 8);
- label.SetBounds(0,
- 0,
- required_size.width() + extra.width(),
- required_size.height() + extra.height());
-
- // Do some basic verifications for all three alignments.
- std::wstring paint_text;
- gfx::Rect text_bounds;
- int flags;
-
- // Centered text.
- label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
- EXPECT_STREQ(test_text.c_str(), paint_text.c_str());
- // The text should be centered horizontally and vertically.
- EXPECT_EQ(extra.width() / 2, text_bounds.x());
- EXPECT_EQ(extra.height() / 2 , text_bounds.y());
- EXPECT_EQ(required_size.width(), text_bounds.width());
- EXPECT_EQ(required_size.height(), text_bounds.height());
- EXPECT_EQ(0, flags);
-
- // Left aligned text.
- label.SetHorizontalAlignment(Label::ALIGN_LEFT);
- paint_text.clear();
- text_bounds.SetRect(0, 0, 0, 0);
- label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
- EXPECT_STREQ(test_text.c_str(), paint_text.c_str());
- // The text should be left aligned horizontally and centered vertically.
- EXPECT_EQ(0, text_bounds.x());
- EXPECT_EQ(extra.height() / 2 , text_bounds.y());
- EXPECT_EQ(required_size.width(), text_bounds.width());
- EXPECT_EQ(required_size.height(), text_bounds.height());
- EXPECT_EQ(0, flags);
-
- // Right aligned text.
- label.SetHorizontalAlignment(Label::ALIGN_RIGHT);
- paint_text.clear();
- text_bounds.SetRect(0, 0, 0, 0);
- label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
- EXPECT_STREQ(test_text.c_str(), paint_text.c_str());
- // The text should be right aligned horizontally and centered vertically.
- EXPECT_EQ(extra.width(), text_bounds.x());
- EXPECT_EQ(extra.height() / 2 , text_bounds.y());
- EXPECT_EQ(required_size.width(), text_bounds.width());
- EXPECT_EQ(required_size.height(), text_bounds.height());
- EXPECT_EQ(0, flags);
-
- // Test single line drawing with a border.
- gfx::Insets border(39, 34, 8, 96);
- label.set_border(Border::CreateEmptyBorder(border.top(),
- border.left(),
- border.bottom(),
- border.right()));
-
- gfx::Size required_size_with_border(label.GetPreferredSize());
- EXPECT_EQ(required_size.width() + border.width(),
- required_size_with_border.width());
- EXPECT_EQ(required_size.height() + border.height(),
- required_size_with_border.height());
- label.SetBounds(0,
- 0,
- required_size_with_border.width() + extra.width(),
- required_size_with_border.height() + extra.height());
-
- // Centered text with border.
- label.SetHorizontalAlignment(Label::ALIGN_CENTER);
- paint_text.clear();
- text_bounds.SetRect(0, 0, 0, 0);
- label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
- EXPECT_STREQ(test_text.c_str(), paint_text.c_str());
- // The text should be centered horizontally and vertically within the border.
- EXPECT_EQ(border.left() + extra.width() / 2, text_bounds.x());
- EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y());
- EXPECT_EQ(required_size.width(), text_bounds.width());
- EXPECT_EQ(required_size.height(), text_bounds.height());
- EXPECT_EQ(0, flags);
-
- // Left aligned text with border.
- label.SetHorizontalAlignment(Label::ALIGN_LEFT);
- paint_text.clear();
- text_bounds.SetRect(0, 0, 0, 0);
- label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
- EXPECT_STREQ(test_text.c_str(), paint_text.c_str());
- // The text should be left aligned horizontally and centered vertically.
- EXPECT_EQ(border.left(), text_bounds.x());
- EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y());
- EXPECT_EQ(required_size.width(), text_bounds.width());
- EXPECT_EQ(required_size.height(), text_bounds.height());
- EXPECT_EQ(0, flags);
-
- // Right aligned text.
- label.SetHorizontalAlignment(Label::ALIGN_RIGHT);
- paint_text.clear();
- text_bounds.SetRect(0, 0, 0, 0);
- label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
- EXPECT_STREQ(test_text.c_str(), paint_text.c_str());
- // The text should be right aligned horizontally and centered vertically.
- EXPECT_EQ(border.left() + extra.width(), text_bounds.x());
- EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y());
- EXPECT_EQ(required_size.width(), text_bounds.width());
- EXPECT_EQ(required_size.height(), text_bounds.height());
- EXPECT_EQ(0, flags);
-}
-
-TEST(LabelTest, DrawMultiLineString) {
- Label label;
-
- // Turn off mirroring so that we don't need to figure out if
- // align right really means align left.
- label.EnableUIMirroringForRTLLanguages(false);
-
- std::wstring test_text(L"Another string\nwith returns\n\n!");
- label.SetText(test_text);
- label.SetMultiLine(true);
- label.SizeToFit(0);
-
- // Do some basic verifications for all three alignments.
- std::wstring paint_text;
- gfx::Rect text_bounds;
- int flags;
- label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
- EXPECT_STREQ(test_text.c_str(), paint_text.c_str());
- EXPECT_EQ(0, text_bounds.x());
- EXPECT_EQ(0, text_bounds.y());
- EXPECT_GT(text_bounds.width(), kMinTextDimension);
- EXPECT_GT(text_bounds.height(), kMinTextDimension);
- EXPECT_EQ(ChromeCanvas::MULTI_LINE | ChromeCanvas::TEXT_ALIGN_CENTER, flags);
- gfx::Rect center_bounds(text_bounds);
-
- label.SetHorizontalAlignment(Label::ALIGN_LEFT);
- paint_text.clear();
- text_bounds.SetRect(0, 0, 0, 0);
- label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
- EXPECT_STREQ(test_text.c_str(), paint_text.c_str());
- EXPECT_EQ(0, text_bounds.x());
- EXPECT_EQ(0, text_bounds.y());
- EXPECT_GT(text_bounds.width(), kMinTextDimension);
- EXPECT_GT(text_bounds.height(), kMinTextDimension);
- EXPECT_EQ(ChromeCanvas::MULTI_LINE | ChromeCanvas::TEXT_ALIGN_LEFT, flags);
-
- label.SetHorizontalAlignment(Label::ALIGN_RIGHT);
- paint_text.clear();
- text_bounds.SetRect(0, 0, 0, 0);
- label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
- EXPECT_STREQ(test_text.c_str(), paint_text.c_str());
- EXPECT_EQ(0, text_bounds.x());
- EXPECT_EQ(0, text_bounds.y());
- EXPECT_GT(text_bounds.width(), kMinTextDimension);
- EXPECT_GT(text_bounds.height(), kMinTextDimension);
- EXPECT_EQ(ChromeCanvas::MULTI_LINE | ChromeCanvas::TEXT_ALIGN_RIGHT, flags);
-
- // Test multiline drawing with a border.
- gfx::Insets border(19, 92, 23, 2);
- label.set_border(Border::CreateEmptyBorder(border.top(),
- border.left(),
- border.bottom(),
- border.right()));
- label.SizeToFit(0);
- label.SetHorizontalAlignment(Label::ALIGN_CENTER);
- paint_text.clear();
- text_bounds.SetRect(0, 0, 0, 0);
- label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
- EXPECT_STREQ(test_text.c_str(), paint_text.c_str());
- EXPECT_EQ(center_bounds.x() + border.left(), text_bounds.x());
- EXPECT_EQ(center_bounds.y() + border.top(), text_bounds.y());
- EXPECT_EQ(center_bounds.width(), text_bounds.width());
- EXPECT_EQ(center_bounds.height(), text_bounds.height());
- EXPECT_EQ(ChromeCanvas::MULTI_LINE | ChromeCanvas::TEXT_ALIGN_CENTER, flags);
-}
-
-} // namespace views
+// Copyright (c) 2006-2008 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 "base/string_util.h"
+#include "chrome/common/l10n_util.h"
+#include "chrome/views/border.h"
+#include "chrome/views/label.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace views {
+
+// All text sizing measurements (width and height) should be greater than this.
+const int kMinTextDimension = 4;
+
+TEST(LabelTest, FontProperty) {
+ Label label;
+ std::wstring font_name(L"courier");
+ ChromeFont font = ChromeFont::CreateFont(font_name, 30);
+ label.SetFont(font);
+ ChromeFont font_used = label.GetFont();
+ EXPECT_STREQ(font_name.c_str(), font_used.FontName().c_str());
+ EXPECT_EQ(30, font_used.FontSize());
+}
+
+TEST(LabelTest, TextProperty) {
+ Label label;
+ std::wstring test_text(L"A random string.");
+ label.SetText(test_text);
+ EXPECT_STREQ(test_text.c_str(), label.GetText().c_str());
+}
+
+TEST(LabelTest, UrlProperty) {
+ Label label;
+ std::string my_url("http://www.orkut.com/some/Random/path");
+ GURL url(my_url);
+ label.SetURL(url);
+ EXPECT_STREQ(my_url.c_str(), label.GetURL().spec().c_str());
+ EXPECT_STREQ(UTF8ToWide(my_url).c_str(), label.GetText().c_str());
+}
+
+TEST(LabelTest, ColorProperty) {
+ Label label;
+ SkColor color = SkColorSetARGB(20, 40, 10, 5);
+ label.SetColor(color);
+ EXPECT_EQ(color, label.GetColor());
+}
+
+TEST(LabelTest, AlignmentProperty) {
+ Label label;
+ bool reverse_alignment =
+ l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT;
+
+ label.SetHorizontalAlignment(Label::ALIGN_RIGHT);
+ EXPECT_EQ(
+ reverse_alignment ? Label::ALIGN_LEFT : Label::ALIGN_RIGHT,
+ label.GetHorizontalAlignment());
+ label.SetHorizontalAlignment(Label::ALIGN_LEFT);
+ EXPECT_EQ(
+ reverse_alignment ? Label::ALIGN_RIGHT : Label::ALIGN_LEFT,
+ label.GetHorizontalAlignment());
+ label.SetHorizontalAlignment(Label::ALIGN_CENTER);
+ EXPECT_EQ(Label::ALIGN_CENTER, label.GetHorizontalAlignment());
+}
+
+TEST(LabelTest, MultiLineProperty) {
+ Label label;
+ EXPECT_FALSE(label.IsMultiLine());
+ label.SetMultiLine(true);
+ EXPECT_TRUE(label.IsMultiLine());
+ label.SetMultiLine(false);
+ EXPECT_FALSE(label.IsMultiLine());
+}
+
+TEST(LabelTest, TooltipProperty) {
+ Label label;
+ std::wstring test_text(L"My cool string.");
+ label.SetText(test_text);
+
+ std::wstring tooltip;
+ EXPECT_TRUE(label.GetTooltipText(0, 0, &tooltip));
+ EXPECT_STREQ(test_text.c_str(), tooltip.c_str());
+
+ std::wstring tooltip_text(L"The tooltip!");
+ label.SetTooltipText(tooltip_text);
+ EXPECT_TRUE(label.GetTooltipText(0, 0, &tooltip));
+ EXPECT_STREQ(tooltip_text.c_str(), tooltip.c_str());
+
+ std::wstring empty_text;
+ label.SetTooltipText(empty_text);
+ EXPECT_TRUE(label.GetTooltipText(0, 0, &tooltip));
+ EXPECT_STREQ(test_text.c_str(), tooltip.c_str());
+
+ // Make the label big enough to hold the text
+ // and expect there to be no tooltip.
+ label.SetBounds(0, 0, 1000, 40);
+ EXPECT_FALSE(label.GetTooltipText(0, 0, &tooltip));
+
+ // Verify that setting the tooltip still shows it.
+ label.SetTooltipText(tooltip_text);
+ EXPECT_TRUE(label.GetTooltipText(0, 0, &tooltip));
+ EXPECT_STREQ(tooltip_text.c_str(), tooltip.c_str());
+ // Clear out the tooltip.
+ label.SetTooltipText(empty_text);
+
+ // Shrink the bounds and the tooltip should come back.
+ label.SetBounds(0, 0, 1, 1);
+ EXPECT_TRUE(label.GetTooltipText(0, 0, &tooltip));
+
+ // Make the label multiline and there is no tooltip again.
+ label.SetMultiLine(true);
+ EXPECT_FALSE(label.GetTooltipText(0, 0, &tooltip));
+
+ // Verify that setting the tooltip still shows it.
+ label.SetTooltipText(tooltip_text);
+ EXPECT_TRUE(label.GetTooltipText(0, 0, &tooltip));
+ EXPECT_STREQ(tooltip_text.c_str(), tooltip.c_str());
+ // Clear out the tooltip.
+ label.SetTooltipText(empty_text);
+}
+
+TEST(LabelTest, Accessibility) {
+ Label label;
+ std::wstring test_text(L"My special text.");
+ label.SetText(test_text);
+
+ VARIANT role;
+ ::VariantInit(&role);
+ EXPECT_TRUE(label.GetAccessibleRole(&role));
+ EXPECT_EQ(VT_I4, role.vt);
+ EXPECT_EQ(ROLE_SYSTEM_TEXT, role.lVal);
+
+ std::wstring name;
+ EXPECT_TRUE(label.GetAccessibleName(&name));
+ EXPECT_STREQ(test_text.c_str(), name.c_str());
+
+ VARIANT state;
+ ::VariantInit(&state);
+ state.vt = VT_I4;
+ state.lVal = 0;
+ EXPECT_TRUE(label.GetAccessibleState(&state));
+ EXPECT_EQ(VT_I4, state.vt);
+ EXPECT_EQ(STATE_SYSTEM_READONLY, state.lVal);
+}
+
+TEST(LabelTest, SingleLineSizing) {
+ Label label;
+ std::wstring test_text(L"A not so random string in one line.");
+ label.SetText(test_text);
+
+ // GetPreferredSize
+ gfx::Size required_size = label.GetPreferredSize();
+ EXPECT_GT(required_size.height(), kMinTextDimension);
+ EXPECT_GT(required_size.width(), kMinTextDimension);
+
+ // Test everything with borders.
+ gfx::Insets border(10, 20, 30, 40);
+ label.set_border(Border::CreateEmptyBorder(border.top(),
+ border.left(),
+ border.bottom(),
+ border.right()));
+
+ // GetPreferredSize and borders.
+ label.SetBounds(0, 0, 0, 0);
+ gfx::Size required_size_with_border = label.GetPreferredSize();
+ EXPECT_EQ(required_size_with_border.height(),
+ required_size.height() + border.height());
+ EXPECT_EQ(required_size_with_border.width(),
+ required_size.width() + border.width());
+}
+
+TEST(LabelTest, MultiLineSizing) {
+ Label label;
+ std::wstring test_text(L"A random string\nwith multiple lines\nand returns!");
+ label.SetText(test_text);
+ label.SetMultiLine(true);
+
+ // GetPreferredSize
+ gfx::Size required_size = label.GetPreferredSize();
+ EXPECT_GT(required_size.height(), kMinTextDimension);
+ EXPECT_GT(required_size.width(), kMinTextDimension);
+
+ // SizeToFit with unlimited width.
+ label.SizeToFit(0);
+ int required_width = label.GetLocalBounds(true).width();
+ EXPECT_GT(required_width, kMinTextDimension);
+
+ // SizeToFit with limited width.
+ label.SizeToFit(required_width - 1);
+ int constrained_width = label.GetLocalBounds(true).width();
+ EXPECT_LT(constrained_width, required_width);
+ EXPECT_GT(constrained_width, kMinTextDimension);
+
+ // Change the width back to the desire width.
+ label.SizeToFit(required_width);
+ EXPECT_EQ(required_width, label.GetLocalBounds(true).width());
+
+ // General tests for GetHeightForWidth.
+ int required_height = label.GetHeightForWidth(required_width);
+ EXPECT_GT(required_height, kMinTextDimension);
+ int height_for_constrained_width = label.GetHeightForWidth(constrained_width);
+ EXPECT_GT(height_for_constrained_width, required_height);
+ // Using the constrained width or the required_width - 1 should give the
+ // same result for the height because the constrainted width is the tight
+ // width when given "required_width - 1" as the max width.
+ EXPECT_EQ(height_for_constrained_width,
+ label.GetHeightForWidth(required_width - 1));
+
+ // Test everything with borders.
+ gfx::Insets border(10, 20, 30, 40);
+ label.set_border(Border::CreateEmptyBorder(border.top(),
+ border.left(),
+ border.bottom(),
+ border.right()));
+
+ // SizeToFit and borders.
+ label.SizeToFit(0);
+ int required_width_with_border = label.GetLocalBounds(true).width();
+ EXPECT_EQ(required_width_with_border, required_width + border.width());
+
+ // GetHeightForWidth and borders.
+ int required_height_with_border =
+ label.GetHeightForWidth(required_width_with_border);
+ EXPECT_EQ(required_height_with_border, required_height + border.height());
+
+ // Test that the border width is subtracted before doing the height
+ // calculation. If it is, then the height will grow when width
+ // is shrunk.
+ int height1 = label.GetHeightForWidth(required_width_with_border - 1);
+ EXPECT_GT(height1, required_height_with_border);
+ EXPECT_EQ(height1, height_for_constrained_width + border.height());
+
+ // GetPreferredSize and borders.
+ label.SetBounds(0, 0, 0, 0);
+ gfx::Size required_size_with_border = label.GetPreferredSize();
+ EXPECT_EQ(required_size_with_border.height(),
+ required_size.height() + border.height());
+ EXPECT_EQ(required_size_with_border.width(),
+ required_size.width() + border.width());
+}
+
+TEST(LabelTest, DrawSingleLineString) {
+ Label label;
+
+ // Turn off mirroring so that we don't need to figure out if
+ // align right really means align left.
+ label.EnableUIMirroringForRTLLanguages(false);
+
+ std::wstring test_text(L"Here's a string with no returns.");
+ label.SetText(test_text);
+ gfx::Size required_size(label.GetPreferredSize());
+ gfx::Size extra(22, 8);
+ label.SetBounds(0,
+ 0,
+ required_size.width() + extra.width(),
+ required_size.height() + extra.height());
+
+ // Do some basic verifications for all three alignments.
+ std::wstring paint_text;
+ gfx::Rect text_bounds;
+ int flags;
+
+ // Centered text.
+ label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
+ EXPECT_STREQ(test_text.c_str(), paint_text.c_str());
+ // The text should be centered horizontally and vertically.
+ EXPECT_EQ(extra.width() / 2, text_bounds.x());
+ EXPECT_EQ(extra.height() / 2 , text_bounds.y());
+ EXPECT_EQ(required_size.width(), text_bounds.width());
+ EXPECT_EQ(required_size.height(), text_bounds.height());
+ EXPECT_EQ(0, flags);
+
+ // Left aligned text.
+ label.SetHorizontalAlignment(Label::ALIGN_LEFT);
+ paint_text.clear();
+ text_bounds.SetRect(0, 0, 0, 0);
+ label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
+ EXPECT_STREQ(test_text.c_str(), paint_text.c_str());
+ // The text should be left aligned horizontally and centered vertically.
+ EXPECT_EQ(0, text_bounds.x());
+ EXPECT_EQ(extra.height() / 2 , text_bounds.y());
+ EXPECT_EQ(required_size.width(), text_bounds.width());
+ EXPECT_EQ(required_size.height(), text_bounds.height());
+ EXPECT_EQ(0, flags);
+
+ // Right aligned text.
+ label.SetHorizontalAlignment(Label::ALIGN_RIGHT);
+ paint_text.clear();
+ text_bounds.SetRect(0, 0, 0, 0);
+ label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
+ EXPECT_STREQ(test_text.c_str(), paint_text.c_str());
+ // The text should be right aligned horizontally and centered vertically.
+ EXPECT_EQ(extra.width(), text_bounds.x());
+ EXPECT_EQ(extra.height() / 2 , text_bounds.y());
+ EXPECT_EQ(required_size.width(), text_bounds.width());
+ EXPECT_EQ(required_size.height(), text_bounds.height());
+ EXPECT_EQ(0, flags);
+
+ // Test single line drawing with a border.
+ gfx::Insets border(39, 34, 8, 96);
+ label.set_border(Border::CreateEmptyBorder(border.top(),
+ border.left(),
+ border.bottom(),
+ border.right()));
+
+ gfx::Size required_size_with_border(label.GetPreferredSize());
+ EXPECT_EQ(required_size.width() + border.width(),
+ required_size_with_border.width());
+ EXPECT_EQ(required_size.height() + border.height(),
+ required_size_with_border.height());
+ label.SetBounds(0,
+ 0,
+ required_size_with_border.width() + extra.width(),
+ required_size_with_border.height() + extra.height());
+
+ // Centered text with border.
+ label.SetHorizontalAlignment(Label::ALIGN_CENTER);
+ paint_text.clear();
+ text_bounds.SetRect(0, 0, 0, 0);
+ label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
+ EXPECT_STREQ(test_text.c_str(), paint_text.c_str());
+ // The text should be centered horizontally and vertically within the border.
+ EXPECT_EQ(border.left() + extra.width() / 2, text_bounds.x());
+ EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y());
+ EXPECT_EQ(required_size.width(), text_bounds.width());
+ EXPECT_EQ(required_size.height(), text_bounds.height());
+ EXPECT_EQ(0, flags);
+
+ // Left aligned text with border.
+ label.SetHorizontalAlignment(Label::ALIGN_LEFT);
+ paint_text.clear();
+ text_bounds.SetRect(0, 0, 0, 0);
+ label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
+ EXPECT_STREQ(test_text.c_str(), paint_text.c_str());
+ // The text should be left aligned horizontally and centered vertically.
+ EXPECT_EQ(border.left(), text_bounds.x());
+ EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y());
+ EXPECT_EQ(required_size.width(), text_bounds.width());
+ EXPECT_EQ(required_size.height(), text_bounds.height());
+ EXPECT_EQ(0, flags);
+
+ // Right aligned text.
+ label.SetHorizontalAlignment(Label::ALIGN_RIGHT);
+ paint_text.clear();
+ text_bounds.SetRect(0, 0, 0, 0);
+ label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
+ EXPECT_STREQ(test_text.c_str(), paint_text.c_str());
+ // The text should be right aligned horizontally and centered vertically.
+ EXPECT_EQ(border.left() + extra.width(), text_bounds.x());
+ EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y());
+ EXPECT_EQ(required_size.width(), text_bounds.width());
+ EXPECT_EQ(required_size.height(), text_bounds.height());
+ EXPECT_EQ(0, flags);
+}
+
+TEST(LabelTest, DrawMultiLineString) {
+ Label label;
+
+ // Turn off mirroring so that we don't need to figure out if
+ // align right really means align left.
+ label.EnableUIMirroringForRTLLanguages(false);
+
+ std::wstring test_text(L"Another string\nwith returns\n\n!");
+ label.SetText(test_text);
+ label.SetMultiLine(true);
+ label.SizeToFit(0);
+
+ // Do some basic verifications for all three alignments.
+ std::wstring paint_text;
+ gfx::Rect text_bounds;
+ int flags;
+ label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
+ EXPECT_STREQ(test_text.c_str(), paint_text.c_str());
+ EXPECT_EQ(0, text_bounds.x());
+ EXPECT_EQ(0, text_bounds.y());
+ EXPECT_GT(text_bounds.width(), kMinTextDimension);
+ EXPECT_GT(text_bounds.height(), kMinTextDimension);
+ EXPECT_EQ(ChromeCanvas::MULTI_LINE | ChromeCanvas::TEXT_ALIGN_CENTER, flags);
+ gfx::Rect center_bounds(text_bounds);
+
+ label.SetHorizontalAlignment(Label::ALIGN_LEFT);
+ paint_text.clear();
+ text_bounds.SetRect(0, 0, 0, 0);
+ label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
+ EXPECT_STREQ(test_text.c_str(), paint_text.c_str());
+ EXPECT_EQ(0, text_bounds.x());
+ EXPECT_EQ(0, text_bounds.y());
+ EXPECT_GT(text_bounds.width(), kMinTextDimension);
+ EXPECT_GT(text_bounds.height(), kMinTextDimension);
+ EXPECT_EQ(ChromeCanvas::MULTI_LINE | ChromeCanvas::TEXT_ALIGN_LEFT, flags);
+
+ label.SetHorizontalAlignment(Label::ALIGN_RIGHT);
+ paint_text.clear();
+ text_bounds.SetRect(0, 0, 0, 0);
+ label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
+ EXPECT_STREQ(test_text.c_str(), paint_text.c_str());
+ EXPECT_EQ(0, text_bounds.x());
+ EXPECT_EQ(0, text_bounds.y());
+ EXPECT_GT(text_bounds.width(), kMinTextDimension);
+ EXPECT_GT(text_bounds.height(), kMinTextDimension);
+ EXPECT_EQ(ChromeCanvas::MULTI_LINE | ChromeCanvas::TEXT_ALIGN_RIGHT, flags);
+
+ // Test multiline drawing with a border.
+ gfx::Insets border(19, 92, 23, 2);
+ label.set_border(Border::CreateEmptyBorder(border.top(),
+ border.left(),
+ border.bottom(),
+ border.right()));
+ label.SizeToFit(0);
+ label.SetHorizontalAlignment(Label::ALIGN_CENTER);
+ paint_text.clear();
+ text_bounds.SetRect(0, 0, 0, 0);
+ label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
+ EXPECT_STREQ(test_text.c_str(), paint_text.c_str());
+ EXPECT_EQ(center_bounds.x() + border.left(), text_bounds.x());
+ EXPECT_EQ(center_bounds.y() + border.top(), text_bounds.y());
+ EXPECT_EQ(center_bounds.width(), text_bounds.width());
+ EXPECT_EQ(center_bounds.height(), text_bounds.height());
+ EXPECT_EQ(ChromeCanvas::MULTI_LINE | ChromeCanvas::TEXT_ALIGN_CENTER, flags);
+}
+
+} // namespace views