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

Side by Side Diff: chrome/browser/ui/cocoa/omnibox/omnibox_view_mac_browsertest.mm

Issue 1857843002: mac: Fix copying from the Omnibox. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm ('k') | ui/base/clipboard/clipboard_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" 5 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
6 6
7 #include "base/strings/sys_string_conversions.h"
8 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_window.h" 10 #include "chrome/browser/ui/browser_window.h"
9 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" 11 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h"
10 #include "chrome/browser/ui/location_bar/location_bar.h" 12 #include "chrome/browser/ui/location_bar/location_bar.h"
11 #include "chrome/test/base/in_process_browser_test.h" 13 #include "chrome/test/base/in_process_browser_test.h"
14 #include "ui/base/clipboard/clipboard_util_mac.h"
12 15
13 class OmniboxViewMacBrowserTest : public InProcessBrowserTest { 16 class OmniboxViewMacBrowserTest : public InProcessBrowserTest {
14 public: 17 public:
15 OmniboxViewMac* GetOmnibox() { 18 OmniboxViewMac* GetOmnibox() {
16 return static_cast<OmniboxViewMac*>( 19 return static_cast<OmniboxViewMac*>(
17 browser()->window()->GetLocationBar()->GetOmniboxView()); 20 browser()->window()->GetLocationBar()->GetOmniboxView());
18 } 21 }
19 }; 22 };
20 23
21 // Verify that the OmniboxViewMac::SetFocus API works. 24 // Verify that the OmniboxViewMac::SetFocus API works.
(...skipping 27 matching lines...) Expand all
49 } 52 }
50 53
51 54
52 // Verify that mouse down sets caret visibility to true. 55 // Verify that mouse down sets caret visibility to true.
53 IN_PROC_BROWSER_TEST_F(OmniboxViewMacBrowserTest, MouseDownCaretVisibility) { 56 IN_PROC_BROWSER_TEST_F(OmniboxViewMacBrowserTest, MouseDownCaretVisibility) {
54 GetOmnibox()->model()->SetCaretVisibility(false); 57 GetOmnibox()->model()->SetCaretVisibility(false);
55 EXPECT_FALSE(GetOmnibox()->model()->is_caret_visible()); 58 EXPECT_FALSE(GetOmnibox()->model()->is_caret_visible());
56 GetOmnibox()->OnMouseDown(0); 59 GetOmnibox()->OnMouseDown(0);
57 EXPECT_TRUE(GetOmnibox()->model()->is_caret_visible()); 60 EXPECT_TRUE(GetOmnibox()->model()->is_caret_visible());
58 } 61 }
62
63 // Verify that copying text from the omnibox into the pasteboard works.
64 IN_PROC_BROWSER_TEST_F(OmniboxViewMacBrowserTest, CopyToPasteboard) {
65 std::string text = "orange yam";
66 NSString* pboard_type = @"com.google.chrome.asdf";
67
68 scoped_refptr<ui::UniquePasteboard> pasteboard = new ui::UniquePasteboard;
69 [[GetOmnibox()->field() currentEditor]
70 setString:base::SysUTF8ToNSString(text)];
71 [[GetOmnibox()->field() currentEditor]
72 setSelectedRange:NSMakeRange(0, text.size())];
73
74 GetOmnibox()->model()->SetUserText(base::UTF8ToUTF16(text));
75 GetOmnibox()->CopyToPasteboard(pasteboard->get());
76
77 NSString* pasteboard_string =
78 [pasteboard->get() stringForType:NSPasteboardTypeString];
79 EXPECT_EQ(text, pasteboard_string.UTF8String);
80
81 // Clear the pasteboard and set some new contents, using a custom Pboard type.
82 [pasteboard->get() clearContents];
83 [pasteboard->get()
84 setString:@"bad result"
85 forType:ui::ClipboardUtil::UTIForPasteboardType(pboard_type)];
86 GetOmnibox()->CopyToPasteboard(pasteboard->get());
87
88 // Check that the custom Pboard type is no longer present.
89 EXPECT_FALSE([pasteboard->get()
90 stringForType:ui::ClipboardUtil::UTIForPasteboardType(pboard_type)]);
91
92 // Check that the contents of the omnibox were copied to the clipboard.
93 pasteboard_string = [pasteboard->get() stringForType:NSPasteboardTypeString];
94 EXPECT_EQ(text, pasteboard_string.UTF8String);
95 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm ('k') | ui/base/clipboard/clipboard_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698