OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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 #include "app/os_exchange_data.h" |
| 6 #include "app/os_exchange_data_provider_win.h" |
| 7 #include "base/pickle.h" |
| 8 #include "chrome/browser/views/extensions/browser_action_drag_data.h" |
| 9 #include "chrome/test/testing_profile.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace { |
| 13 |
| 14 OSExchangeData::Provider* CloneProvider(const OSExchangeData& data) { |
| 15 return new OSExchangeDataProviderWin( |
| 16 OSExchangeDataProviderWin::GetIDataObject(data)); |
| 17 } |
| 18 |
| 19 } // namespace |
| 20 |
| 21 typedef testing::Test BrowserActionDragDataTest; |
| 22 |
| 23 TEST_F(BrowserActionDragDataTest, ArbitraryFormat) { |
| 24 TestingProfile profile; |
| 25 profile.SetID(L"id"); |
| 26 |
| 27 OSExchangeData data; |
| 28 data.SetURL(GURL("http://www.google.com"), L"Title"); |
| 29 |
| 30 // We only support our format, so this should not succeed. |
| 31 BrowserActionDragData drag_data; |
| 32 EXPECT_FALSE(drag_data.Read(OSExchangeData(CloneProvider(data)))); |
| 33 } |
| 34 |
| 35 TEST_F(BrowserActionDragDataTest, BrowserActionDragDataFormat) { |
| 36 TestingProfile profile; |
| 37 profile.SetID(L"id"); |
| 38 |
| 39 const std::string extension_id = "42"; |
| 40 Pickle pickle; |
| 41 pickle.WriteWString(profile.GetPath().ToWStringHack()); |
| 42 pickle.WriteString(extension_id); |
| 43 pickle.WriteInt(42); |
| 44 |
| 45 OSExchangeData data; |
| 46 data.SetPickledData(BrowserActionDragData::GetBrowserActionCustomFormat(), |
| 47 pickle); |
| 48 |
| 49 BrowserActionDragData drag_data; |
| 50 EXPECT_TRUE(drag_data.Read(OSExchangeData(CloneProvider(data)))); |
| 51 ASSERT_TRUE(drag_data.IsFromProfile(profile.GetOriginalProfile())); |
| 52 ASSERT_STREQ(extension_id.c_str(), drag_data.id().c_str()); |
| 53 ASSERT_EQ(42, drag_data.index()); |
| 54 } |
OLD | NEW |