Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "base/mac/scoped_nsautorelease_pool.h" | 5 #include "base/mac/scoped_nsautorelease_pool.h" |
| 6 #import "base/memory/scoped_nsobject.h" | 6 #import "base/memory/scoped_nsobject.h" |
| 7 #include "base/sys_string_conversions.h" | 7 #include "base/sys_string_conversions.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 9 #include "content/browser/renderer_host/test_render_view_host.h" |
| 10 #import "chrome/browser/ui/cocoa/tab_contents/web_drop_target.h" | |
| 11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
| 12 #include "content/browser/tab_contents/test_tab_contents.h" | 10 #include "content/browser/tab_contents/test_tab_contents.h" |
| 11 #import "content/browser/tab_contents/web_drag_dest_mac.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #import "third_party/mozilla/NSPasteboard+Utils.h" | 13 #import "third_party/mozilla/NSPasteboard+Utils.h" |
| 15 #import "ui/base/dragdrop/cocoa_dnd_util.h" | 14 #import "ui/base/dragdrop/cocoa_dnd_util.h" |
| 15 #import "ui/base/test/ui_cocoa_test_helper.h" | |
| 16 #include "webkit/glue/webdropdata.h" | 16 #include "webkit/glue/webdropdata.h" |
| 17 | 17 |
| 18 class WebDropTargetTest : public ChromeRenderViewHostTestHarness { | 18 class WebDragDestTest : public RenderViewHostTestHarness { |
| 19 public: | 19 public: |
| 20 virtual void SetUp() { | 20 virtual void SetUp() { |
| 21 ChromeRenderViewHostTestHarness::SetUp(); | 21 RenderViewHostTestHarness::SetUp(); |
| 22 CocoaTest::BootstrapCocoa(); | 22 drop_target_.reset([[WebDragDest alloc] initWithTabContents:contents()]); |
| 23 drop_target_.reset([[WebDropTarget alloc] initWithTabContents:contents()]); | |
| 24 } | 23 } |
| 25 | 24 |
| 26 void PutURLOnPasteboard(NSString* urlString, NSPasteboard* pboard) { | 25 void PutURLOnPasteboard(NSString* urlString, NSPasteboard* pboard) { |
| 27 [pboard declareTypes:[NSArray arrayWithObject:NSURLPboardType] | 26 [pboard declareTypes:[NSArray arrayWithObject:NSURLPboardType] |
| 28 owner:nil]; | 27 owner:nil]; |
| 29 NSURL* url = [NSURL URLWithString:urlString]; | 28 NSURL* url = [NSURL URLWithString:urlString]; |
| 30 EXPECT_TRUE(url); | 29 EXPECT_TRUE(url); |
| 31 [url writeToPasteboard:pboard]; | 30 [url writeToPasteboard:pboard]; |
| 32 } | 31 } |
| 33 | 32 |
| 34 void PutCoreURLAndTitleOnPasteboard(NSString* urlString, NSString* title, | 33 void PutCoreURLAndTitleOnPasteboard(NSString* urlString, NSString* title, |
| 35 NSPasteboard* pboard) { | 34 NSPasteboard* pboard) { |
| 36 [pboard | 35 [pboard |
| 37 declareTypes:[NSArray arrayWithObjects:kCorePasteboardFlavorType_url, | 36 declareTypes:[NSArray arrayWithObjects:kCorePasteboardFlavorType_url, |
| 38 kCorePasteboardFlavorType_urln, | 37 kCorePasteboardFlavorType_urln, |
| 39 nil] | 38 nil] |
| 40 owner:nil]; | 39 owner:nil]; |
| 41 [pboard setString:urlString | 40 [pboard setString:urlString |
| 42 forType:kCorePasteboardFlavorType_url]; | 41 forType:kCorePasteboardFlavorType_url]; |
| 43 [pboard setString:title | 42 [pboard setString:title |
| 44 forType:kCorePasteboardFlavorType_urln]; | 43 forType:kCorePasteboardFlavorType_urln]; |
| 45 } | 44 } |
| 46 | 45 |
| 47 base::mac::ScopedNSAutoreleasePool pool_; | 46 base::mac::ScopedNSAutoreleasePool pool_; |
| 48 scoped_nsobject<WebDropTarget> drop_target_; | 47 scoped_nsobject<WebDragDest> drop_target_; |
|
jochen (gone - plz use gerrit)
2011/11/01 19:26:03
nit rename variable as well?
Avi (use Gerrit)
2011/11/01 20:19:23
Done.
| |
| 49 }; | 48 }; |
| 50 | 49 |
| 51 // Make sure nothing leaks. | 50 // Make sure nothing leaks. |
| 52 TEST_F(WebDropTargetTest, Init) { | 51 TEST_F(WebDragDestTest, Init) { |
| 53 EXPECT_TRUE(drop_target_); | 52 EXPECT_TRUE(drop_target_); |
| 54 } | 53 } |
| 55 | 54 |
| 56 // Test flipping of coordinates given a point in window coordinates. | 55 // Test flipping of coordinates given a point in window coordinates. |
| 57 TEST_F(WebDropTargetTest, Flip) { | 56 TEST_F(WebDragDestTest, Flip) { |
| 58 NSPoint windowPoint = NSZeroPoint; | 57 NSPoint windowPoint = NSZeroPoint; |
| 59 scoped_nsobject<NSWindow> window([[CocoaTestHelperWindow alloc] init]); | 58 scoped_nsobject<NSWindow> window([[CocoaTestHelperWindow alloc] init]); |
| 60 NSPoint viewPoint = | 59 NSPoint viewPoint = |
| 61 [drop_target_ flipWindowPointToView:windowPoint | 60 [drop_target_ flipWindowPointToView:windowPoint |
| 62 view:[window contentView]]; | 61 view:[window contentView]]; |
| 63 NSPoint screenPoint = | 62 NSPoint screenPoint = |
| 64 [drop_target_ flipWindowPointToScreen:windowPoint | 63 [drop_target_ flipWindowPointToScreen:windowPoint |
| 65 view:[window contentView]]; | 64 view:[window contentView]]; |
| 66 EXPECT_EQ(0, viewPoint.x); | 65 EXPECT_EQ(0, viewPoint.x); |
| 67 EXPECT_EQ(600, viewPoint.y); | 66 EXPECT_EQ(600, viewPoint.y); |
| 68 EXPECT_EQ(0, screenPoint.x); | 67 EXPECT_EQ(0, screenPoint.x); |
| 69 // We can't put a value on the screen size since everyone will have a | 68 // We can't put a value on the screen size since everyone will have a |
| 70 // different one. | 69 // different one. |
| 71 EXPECT_NE(0, screenPoint.y); | 70 EXPECT_NE(0, screenPoint.y); |
| 72 } | 71 } |
| 73 | 72 |
| 74 TEST_F(WebDropTargetTest, URL) { | 73 TEST_F(WebDragDestTest, URL) { |
| 75 NSPasteboard* pboard = nil; | 74 NSPasteboard* pboard = nil; |
| 76 NSString* url = nil; | 75 NSString* url = nil; |
| 77 NSString* title = nil; | 76 NSString* title = nil; |
| 78 GURL result_url; | 77 GURL result_url; |
| 79 string16 result_title; | 78 string16 result_title; |
| 80 | 79 |
| 81 // Put a URL on the pasteboard and check it. | 80 // Put a URL on the pasteboard and check it. |
| 82 pboard = [NSPasteboard pasteboardWithUniqueName]; | 81 pboard = [NSPasteboard pasteboardWithUniqueName]; |
| 83 url = @"http://www.google.com/"; | 82 url = @"http://www.google.com/"; |
| 84 PutURLOnPasteboard(url, pboard); | 83 PutURLOnPasteboard(url, pboard); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 forType:NSFilenamesPboardType]; | 127 forType:NSFilenamesPboardType]; |
| 129 EXPECT_FALSE(ui::PopulateURLAndTitleFromPasteboard( | 128 EXPECT_FALSE(ui::PopulateURLAndTitleFromPasteboard( |
| 130 &result_url, &result_title, pboard, NO)); | 129 &result_url, &result_title, pboard, NO)); |
| 131 EXPECT_TRUE(ui::PopulateURLAndTitleFromPasteboard( | 130 EXPECT_TRUE(ui::PopulateURLAndTitleFromPasteboard( |
| 132 &result_url, &result_title, pboard, YES)); | 131 &result_url, &result_title, pboard, YES)); |
| 133 EXPECT_EQ("file://localhost/bin/sh", result_url.spec()); | 132 EXPECT_EQ("file://localhost/bin/sh", result_url.spec()); |
| 134 EXPECT_EQ("sh", UTF16ToUTF8(result_title)); | 133 EXPECT_EQ("sh", UTF16ToUTF8(result_title)); |
| 135 [pboard releaseGlobally]; | 134 [pboard releaseGlobally]; |
| 136 } | 135 } |
| 137 | 136 |
| 138 TEST_F(WebDropTargetTest, Data) { | 137 TEST_F(WebDragDestTest, Data) { |
| 139 WebDropData data; | 138 WebDropData data; |
| 140 NSPasteboard* pboard = [NSPasteboard pasteboardWithUniqueName]; | 139 NSPasteboard* pboard = [NSPasteboard pasteboardWithUniqueName]; |
| 141 | 140 |
| 142 PutURLOnPasteboard(@"http://www.google.com", pboard); | 141 PutURLOnPasteboard(@"http://www.google.com", pboard); |
| 143 [pboard addTypes:[NSArray arrayWithObjects:NSHTMLPboardType, | 142 [pboard addTypes:[NSArray arrayWithObjects:NSHTMLPboardType, |
| 144 NSStringPboardType, nil] | 143 NSStringPboardType, nil] |
| 145 owner:nil]; | 144 owner:nil]; |
| 146 NSString* htmlString = @"<html><body><b>hi there</b></body></html>"; | 145 NSString* htmlString = @"<html><body><b>hi there</b></body></html>"; |
| 147 NSString* textString = @"hi there"; | 146 NSString* textString = @"hi there"; |
| 148 [pboard setString:htmlString forType:NSHTMLPboardType]; | 147 [pboard setString:htmlString forType:NSHTMLPboardType]; |
| 149 [pboard setString:textString forType:NSStringPboardType]; | 148 [pboard setString:textString forType:NSStringPboardType]; |
| 150 [drop_target_ populateWebDropData:&data fromPasteboard:pboard]; | 149 [drop_target_ populateWebDropData:&data fromPasteboard:pboard]; |
| 151 EXPECT_EQ(data.url.spec(), "http://www.google.com/"); | 150 EXPECT_EQ(data.url.spec(), "http://www.google.com/"); |
| 152 EXPECT_EQ(base::SysNSStringToUTF16(textString), data.plain_text); | 151 EXPECT_EQ(base::SysNSStringToUTF16(textString), data.plain_text); |
| 153 EXPECT_EQ(base::SysNSStringToUTF16(htmlString), data.text_html); | 152 EXPECT_EQ(base::SysNSStringToUTF16(htmlString), data.text_html); |
| 154 | 153 |
| 155 [pboard releaseGlobally]; | 154 [pboard releaseGlobally]; |
| 156 } | 155 } |
| OLD | NEW |