| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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/scoped_nsautorelease_pool.h" | 5 #include "base/scoped_nsautorelease_pool.h" |
| 6 #include "base/sys_string_conversions.h" | 6 #include "base/sys_string_conversions.h" |
| 7 #import "chrome/browser/cocoa/cocoa_test_helper.h" | 7 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
| 8 #import "chrome/browser/cocoa/web_drop_target.h" | 8 #import "chrome/browser/cocoa/web_drop_target.h" |
| 9 #include "chrome/browser/renderer_host/test/test_render_view_host.h" | 9 #include "chrome/browser/renderer_host/test/test_render_view_host.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #import "third_party/mozilla/include/NSPasteboard+Utils.h" | 11 #import "third_party/mozilla/include/NSPasteboard+Utils.h" |
| 12 #include "webkit/glue/webdropdata.h" | 12 #include "webkit/glue/webdropdata.h" |
| 13 | 13 |
| 14 class WebDropTargetTest : public RenderViewHostTestHarness { | 14 class WebDropTargetTest : public RenderViewHostTestHarness { |
| 15 public: | 15 public: |
| 16 WebDropTargetTest() { | 16 virtual void SetUp() { |
| 17 drop_target_.reset([[WebDropTarget alloc] initWithTabContents:contents()]); | 17 RenderViewHostTestHarness::SetUp(); |
| 18 } | 18 CocoaTest::BootstrapCocoa(); |
| 19 | 19 drop_target_.reset([[WebDropTarget alloc] initWithTabContents:contents()]); |
| 20 virtual ~WebDropTargetTest() { | |
| 21 RenderViewHostTestHarness::TearDown(); | |
| 22 | |
| 23 } | 20 } |
| 24 | 21 |
| 25 void PutURLOnPasteboard(NSString* urlString, NSPasteboard* pboard) { | 22 void PutURLOnPasteboard(NSString* urlString, NSPasteboard* pboard) { |
| 26 [pboard declareTypes:[NSArray arrayWithObject:NSURLPboardType] | 23 [pboard declareTypes:[NSArray arrayWithObject:NSURLPboardType] |
| 27 owner:nil]; | 24 owner:nil]; |
| 28 NSURL* url = [NSURL URLWithString:urlString]; | 25 NSURL* url = [NSURL URLWithString:urlString]; |
| 29 EXPECT_TRUE(url); | 26 EXPECT_TRUE(url); |
| 30 [url writeToPasteboard:pboard]; | 27 [url writeToPasteboard:pboard]; |
| 31 } | 28 } |
| 32 | 29 |
| 33 base::ScopedNSAutoreleasePool pool_; | 30 base::ScopedNSAutoreleasePool pool_; |
| 34 CocoaTestHelper cocoa_helper_; | |
| 35 scoped_nsobject<WebDropTarget> drop_target_; | 31 scoped_nsobject<WebDropTarget> drop_target_; |
| 36 }; | 32 }; |
| 37 | 33 |
| 38 // Make sure nothing leaks. | 34 // Make sure nothing leaks. |
| 39 TEST_F(WebDropTargetTest, Init) { | 35 TEST_F(WebDropTargetTest, Init) { |
| 40 EXPECT_TRUE(drop_target_); | 36 EXPECT_TRUE(drop_target_); |
| 41 } | 37 } |
| 42 | 38 |
| 43 // Test flipping of coordinates given a point in window coordinates. | 39 // Test flipping of coordinates given a point in window coordinates. |
| 44 TEST_F(WebDropTargetTest, Flip) { | 40 TEST_F(WebDropTargetTest, Flip) { |
| 45 NSPoint windowPoint = NSZeroPoint; | 41 NSPoint windowPoint = NSZeroPoint; |
| 42 scoped_nsobject<NSWindow> window([[CocoaTestHelperWindow alloc] init]); |
| 46 NSPoint viewPoint = | 43 NSPoint viewPoint = |
| 47 [drop_target_ flipWindowPointToView:windowPoint | 44 [drop_target_ flipWindowPointToView:windowPoint |
| 48 view:cocoa_helper_.contentView()]; | 45 view:[window contentView]]; |
| 49 NSPoint screenPoint = | 46 NSPoint screenPoint = |
| 50 [drop_target_ flipWindowPointToScreen:windowPoint | 47 [drop_target_ flipWindowPointToScreen:windowPoint |
| 51 view:cocoa_helper_.contentView()]; | 48 view:[window contentView]]; |
| 52 EXPECT_EQ(viewPoint.x, 0); | 49 EXPECT_EQ(viewPoint.x, 0); |
| 53 EXPECT_EQ(viewPoint.y, 600); | 50 EXPECT_EQ(viewPoint.y, 600); |
| 54 EXPECT_EQ(screenPoint.x, 0); | 51 EXPECT_EQ(screenPoint.x, 0); |
| 55 // We can't put a value on the screen size since everyone will have a | 52 // We can't put a value on the screen size since everyone will have a |
| 56 // different one. | 53 // different one. |
| 57 EXPECT_NE(screenPoint.y, 0); | 54 EXPECT_NE(screenPoint.y, 0); |
| 58 } | 55 } |
| 59 | 56 |
| 60 TEST_F(WebDropTargetTest, URL) { | 57 TEST_F(WebDropTargetTest, URL) { |
| 61 WebDropData data; | 58 WebDropData data; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 EXPECT_EQ(data.plain_text, base::SysNSStringToUTF16(textString)); | 98 EXPECT_EQ(data.plain_text, base::SysNSStringToUTF16(textString)); |
| 102 EXPECT_EQ(data.text_html, base::SysNSStringToUTF16(htmlString)); | 99 EXPECT_EQ(data.text_html, base::SysNSStringToUTF16(htmlString)); |
| 103 | 100 |
| 104 [pboard releaseGlobally]; | 101 [pboard releaseGlobally]; |
| 105 } | 102 } |
| 106 | 103 |
| 107 TEST_F(WebDropTargetTest, EnterExitDrop) { | 104 TEST_F(WebDropTargetTest, EnterExitDrop) { |
| 108 // TODO(pinkerton): Call enter/exit/drop and see what happens. This is a bit | 105 // TODO(pinkerton): Call enter/exit/drop and see what happens. This is a bit |
| 109 // harder to test. | 106 // harder to test. |
| 110 } | 107 } |
| OLD | NEW |