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

Side by Side Diff: components/bookmarks/browser/bookmark_utils_unittest.cc

Issue 437423005: Show paste option on right click of bookmark bar if some URL is copied from outside browser or from… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added unit tests Created 6 years, 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/bookmarks/browser/bookmark_utils.h" 5 #include "components/bookmarks/browser/bookmark_utils.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 GURL("http://www.google.com")); 266 GURL("http://www.google.com"));
267 267
268 // Copy a node to the clipboard. 268 // Copy a node to the clipboard.
269 std::vector<const BookmarkNode*> nodes; 269 std::vector<const BookmarkNode*> nodes;
270 nodes.push_back(node); 270 nodes.push_back(node);
271 CopyToClipboard(model.get(), nodes, false); 271 CopyToClipboard(model.get(), nodes, false);
272 272
273 // And make sure we can paste a bookmark from the clipboard. 273 // And make sure we can paste a bookmark from the clipboard.
274 EXPECT_TRUE(CanPasteFromClipboard(model.get(), model->bookmark_bar_node())); 274 EXPECT_TRUE(CanPasteFromClipboard(model.get(), model->bookmark_bar_node()));
275 275
276 // Write some valid url to the clipboard.
277 ui::ScopedClipboardWriter clipboard_writer(
278 ui::Clipboard::GetForCurrentThread(), ui::CLIPBOARD_TYPE_COPY_PASTE);
279 clipboard_writer.WriteText(ASCIIToUTF16("http://www.google.com"));
280
281 // Now we should be able to paste from the clipboard.
282 EXPECT_TRUE(CanPasteFromClipboard(model.get(), model->bookmark_bar_node()));
283
276 // Write some text to the clipboard. 284 // Write some text to the clipboard.
277 { 285 {
278 ui::ScopedClipboardWriter clipboard_writer( 286 ui::ScopedClipboardWriter clipboard_writer(
279 ui::Clipboard::GetForCurrentThread(), 287 ui::Clipboard::GetForCurrentThread(),
280 ui::CLIPBOARD_TYPE_COPY_PASTE); 288 ui::CLIPBOARD_TYPE_COPY_PASTE);
281 clipboard_writer.WriteText(ASCIIToUTF16("foo")); 289 clipboard_writer.WriteText(ASCIIToUTF16("foo"));
282 } 290 }
283 291
284 // Now we shouldn't be able to paste from the clipboard. 292 // Now we shouldn't be able to paste from the clipboard.
285 EXPECT_FALSE(CanPasteFromClipboard(model.get(), model->bookmark_bar_node())); 293 EXPECT_FALSE(CanPasteFromClipboard(model.get(), model->bookmark_bar_node()));
(...skipping 27 matching lines...) Expand all
313 321
314 // Verify that the pasted node contains the same meta info. 322 // Verify that the pasted node contains the same meta info.
315 const BookmarkNode* pasted = folder->GetChild(0); 323 const BookmarkNode* pasted = folder->GetChild(0);
316 ASSERT_TRUE(pasted->GetMetaInfoMap()); 324 ASSERT_TRUE(pasted->GetMetaInfoMap());
317 EXPECT_EQ(2u, pasted->GetMetaInfoMap()->size()); 325 EXPECT_EQ(2u, pasted->GetMetaInfoMap()->size());
318 std::string value; 326 std::string value;
319 EXPECT_TRUE(pasted->GetMetaInfo("somekey", &value)); 327 EXPECT_TRUE(pasted->GetMetaInfo("somekey", &value));
320 EXPECT_EQ("somevalue", value); 328 EXPECT_EQ("somevalue", value);
321 EXPECT_TRUE(pasted->GetMetaInfo("someotherkey", &value)); 329 EXPECT_TRUE(pasted->GetMetaInfo("someotherkey", &value));
322 EXPECT_EQ("someothervalue", value); 330 EXPECT_EQ("someothervalue", value);
331
332 // Write some valid url to clipboard
333 ui::ScopedClipboardWriter clipboard_writer(
334 ui::Clipboard::GetForCurrentThread(), ui::CLIPBOARD_TYPE_COPY_PASTE);
335 clipboard_writer.WriteText(ASCIIToUTF16("http://www.google.com"));
336
337 // We should be able to paste from clipboard.
338 EXPECT_TRUE(CanPasteFromClipboard(model.get(), folder));
339
340 PasteFromClipboard(model.get(), folder, 1);
341 ASSERT_EQ(2, folder->child_count());
323 } 342 }
324 343
325 #if defined(OS_LINUX) || defined(OS_MACOSX) 344 #if defined(OS_LINUX) || defined(OS_MACOSX)
326 // http://crbug.com/396472 345 // http://crbug.com/396472
327 #define MAYBE_CutToClipboard DISABLED_CutToClipboard 346 #define MAYBE_CutToClipboard DISABLED_CutToClipboard
328 #else 347 #else
329 #define MAYBE_CutToClipboard CutToClipboard 348 #define MAYBE_CutToClipboard CutToClipboard
330 #endif 349 #endif
331 TEST_F(BookmarkUtilsTest, MAYBE_CutToClipboard) { 350 TEST_F(BookmarkUtilsTest, MAYBE_CutToClipboard) {
332 test::TestBookmarkClient client; 351 test::TestBookmarkClient client;
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 model->GetNodesByURL(url, &nodes); 507 model->GetNodesByURL(url, &nodes);
489 ASSERT_EQ(1u, nodes.size()); 508 ASSERT_EQ(1u, nodes.size());
490 EXPECT_TRUE(model->bookmark_bar_node()->empty()); 509 EXPECT_TRUE(model->bookmark_bar_node()->empty());
491 EXPECT_TRUE(model->other_node()->empty()); 510 EXPECT_TRUE(model->other_node()->empty());
492 EXPECT_TRUE(model->mobile_node()->empty()); 511 EXPECT_TRUE(model->mobile_node()->empty());
493 EXPECT_EQ(1, extra_node->child_count()); 512 EXPECT_EQ(1, extra_node->child_count());
494 } 513 }
495 514
496 } // namespace 515 } // namespace
497 } // namespace bookmarks 516 } // namespace bookmarks
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698