• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2009 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#import "chrome/browser/autocomplete/autocomplete_edit_view_mac.h"
6
7#include "base/string_util.h"
8#include "base/sys_string_conversions.h"
9#include "base/utf_string_conversions.h"
10#include "chrome/browser/autocomplete/autocomplete.h"
11#include "testing/platform_test.h"
12#include "ui/base/clipboard/clipboard.h"
13#include "ui/base/clipboard/scoped_clipboard_writer.h"
14#include "ui/gfx/size.h"
15
16namespace {
17
18TEST(AutocompleteEditViewMacTest, GetClipboardText) {
19  ui::Clipboard clipboard;
20  string16 text;
21
22  // Does an empty clipboard get empty text?
23  clipboard.WriteObjects(ui::Clipboard::ObjectMap());
24  text = AutocompleteEditViewMac::GetClipboardText(&clipboard);
25  EXPECT_EQ(string16(), text);
26
27  const string16 plainText(ASCIIToUTF16("test text"));
28  const std::string url("http://www.example.com/");
29  const string16 title(ASCIIToUTF16("The Example Company")), title_result;
30
31  // Can we pull straight text off the clipboard?
32  {
33    ui::ScopedClipboardWriter clipboard_writer(&clipboard);
34    clipboard_writer.WriteText(plainText);
35  }
36
37  text = AutocompleteEditViewMac::GetClipboardText(&clipboard);
38  EXPECT_EQ(plainText, text);
39
40  // Can we pull a bookmark off the clipboard?
41  {
42    ui::ScopedClipboardWriter clipboard_writer(&clipboard);
43    clipboard_writer.WriteBookmark(title, url);
44  }
45
46  text = AutocompleteEditViewMac::GetClipboardText(&clipboard);
47  EXPECT_EQ(ASCIIToUTF16(url), text);
48
49  // Do we pull text in preference to a bookmark?
50  {
51    ui::ScopedClipboardWriter clipboard_writer(&clipboard);
52    clipboard_writer.WriteText(plainText);
53    clipboard_writer.WriteBookmark(title, url);
54  }
55
56  text = AutocompleteEditViewMac::GetClipboardText(&clipboard);
57  EXPECT_EQ(plainText, text);
58
59  // Do we get nothing if there is neither text nor a bookmark?
60  {
61    const string16 markup(ASCIIToUTF16("<strong>Hi!</string>"));
62    ui::ScopedClipboardWriter clipboard_writer(&clipboard);
63    clipboard_writer.WriteHTML(markup, url);
64  }
65
66  text = AutocompleteEditViewMac::GetClipboardText(&clipboard);
67  EXPECT_TRUE(text.empty());
68}
69
70TEST(AutocompleteEditViewMacTest, GetFieldFont) {
71  EXPECT_TRUE(AutocompleteEditViewMac::GetFieldFont());
72}
73
74}  // namespace
75