| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "app/os_exchange_data.h" | 5 #include "app/os_exchange_data.h" |
| 6 #include "base/scoped_ptr.h" | 6 #include "base/scoped_ptr.h" |
| 7 #include "chrome/browser/bookmarks/bookmark_drag_data.h" | 7 #include "chrome/browser/bookmarks/bookmark_drag_data.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_model.h" | 8 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 9 #include "chrome/test/testing_profile.h" | 9 #include "chrome/test/testing_profile.h" |
| 10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 typedef testing::Test BookmarkDragDataTest; | 13 typedef testing::Test BookmarkDragDataTest; |
| 14 | 14 |
| 15 // Makes sure BookmarkDragData is initially invalid. | 15 // Makes sure BookmarkDragData is initially invalid. |
| 16 TEST_F(BookmarkDragDataTest, InitialState) { | 16 TEST_F(BookmarkDragDataTest, InitialState) { |
| 17 BookmarkDragData data; | 17 BookmarkDragData data; |
| 18 EXPECT_FALSE(data.is_valid()); | 18 EXPECT_FALSE(data.is_valid()); |
| 19 } | 19 } |
| 20 | 20 |
| 21 // Makes sure reading bogus data leaves the BookmarkDragData invalid. | 21 // Makes sure reading bogus data leaves the BookmarkDragData invalid. |
| 22 TEST_F(BookmarkDragDataTest, BogusRead) { | 22 TEST_F(BookmarkDragDataTest, BogusRead) { |
| 23 scoped_refptr<OSExchangeData> data(new OSExchangeData()); | 23 scoped_refptr<OSExchangeData> data(new OSExchangeData()); |
| 24 BookmarkDragData drag_data; | 24 BookmarkDragData drag_data; |
| 25 EXPECT_FALSE(drag_data.Read(data.get())); | 25 EXPECT_FALSE(drag_data.Read(OSExchangeData(data.get()))); |
| 26 EXPECT_FALSE(drag_data.is_valid()); | 26 EXPECT_FALSE(drag_data.is_valid()); |
| 27 } | 27 } |
| 28 | 28 |
| 29 // Writes a URL to the clipboard and make sure BookmarkDragData can correctly | 29 // Writes a URL to the clipboard and make sure BookmarkDragData can correctly |
| 30 // read it. | 30 // read it. |
| 31 TEST_F(BookmarkDragDataTest, JustURL) { | 31 TEST_F(BookmarkDragDataTest, JustURL) { |
| 32 const GURL url("http://google.com"); | 32 const GURL url("http://google.com"); |
| 33 const std::wstring title(L"title"); | 33 const std::wstring title(L"title"); |
| 34 | 34 |
| 35 scoped_refptr<OSExchangeData> data(new OSExchangeData()); | 35 scoped_refptr<OSExchangeData> data(new OSExchangeData()); |
| 36 data->SetURL(url, title); | 36 data->SetURL(url, title); |
| 37 | 37 |
| 38 BookmarkDragData drag_data; | 38 BookmarkDragData drag_data; |
| 39 EXPECT_TRUE(drag_data.Read(data.get())); | 39 EXPECT_TRUE(drag_data.Read(OSExchangeData(data.get()))); |
| 40 EXPECT_TRUE(drag_data.is_valid()); | 40 EXPECT_TRUE(drag_data.is_valid()); |
| 41 ASSERT_EQ(1, drag_data.elements.size()); | 41 ASSERT_EQ(1, drag_data.elements.size()); |
| 42 EXPECT_TRUE(drag_data.elements[0].is_url); | 42 EXPECT_TRUE(drag_data.elements[0].is_url); |
| 43 EXPECT_TRUE(drag_data.elements[0].url == url); | 43 EXPECT_TRUE(drag_data.elements[0].url == url); |
| 44 EXPECT_TRUE(drag_data.elements[0].title == title); | 44 EXPECT_TRUE(drag_data.elements[0].title == title); |
| 45 EXPECT_EQ(0, drag_data.elements[0].children.size()); | 45 EXPECT_EQ(0, drag_data.elements[0].children.size()); |
| 46 } | 46 } |
| 47 | 47 |
| 48 TEST_F(BookmarkDragDataTest, URL) { | 48 TEST_F(BookmarkDragDataTest, URL) { |
| 49 // Write a single node representing a URL to the clipboard. | 49 // Write a single node representing a URL to the clipboard. |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 // And make sure we get the node back. | 206 // And make sure we get the node back. |
| 207 std::vector<BookmarkNode*> read_nodes = read_data.GetNodes(&profile); | 207 std::vector<BookmarkNode*> read_nodes = read_data.GetNodes(&profile); |
| 208 ASSERT_EQ(2, read_nodes.size()); | 208 ASSERT_EQ(2, read_nodes.size()); |
| 209 EXPECT_TRUE(read_nodes[0] == group); | 209 EXPECT_TRUE(read_nodes[0] == group); |
| 210 EXPECT_TRUE(read_nodes[1] == url_node); | 210 EXPECT_TRUE(read_nodes[1] == url_node); |
| 211 | 211 |
| 212 // Asking for the first node should return NULL with more than one element | 212 // Asking for the first node should return NULL with more than one element |
| 213 // present. | 213 // present. |
| 214 EXPECT_TRUE(read_data.GetFirstNode(&profile) == NULL); | 214 EXPECT_TRUE(read_data.GetFirstNode(&profile) == NULL); |
| 215 } | 215 } |
| OLD | NEW |