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

Unified Diff: chrome/browser/ui/views/frame/browser_root_view_unittest.cc

Issue 2322253004: Drag and dropping text, parsable as url (Closed)
Patch Set: Moving url logic out of os_exchange_data Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/views/tabs/tab_strip.cc » ('j') | chrome/browser/ui/views/tabs/tab_strip.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/frame/browser_root_view_unittest.cc
diff --git a/chrome/browser/ui/views/frame/browser_root_view_unittest.cc b/chrome/browser/ui/views/frame/browser_root_view_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c44d18947bfcfc660ebb4ad2a8385eb937d88b6e
--- /dev/null
+++ b/chrome/browser/ui/views/frame/browser_root_view_unittest.cc
@@ -0,0 +1,92 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/views/frame/browser_root_view.h"
+
+#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/views/frame/browser_view.h"
+#include "chrome/browser/ui/views/frame/test_with_browser_view.h"
+#include "chrome/browser/ui/views/tabs/tab_strip.h"
+#include "content/public/browser/web_contents.h"
+#include "ui/base/dragdrop/os_exchange_data.h"
+#include "url/gurl.h"
+#include "url/url_constants.h"
+
+constexpr char kSearchEngineHost[] = "www.google.com";
+
+// This text is a valid url but it's very unlikely that user meant it to be used
+// as one. We ought to process it as query unless the only way to interpret it
+// is as url.
+constexpr char kVeryUnlikelyUrl[] = "query: abcd";
+
+class BrowserRootViewTest : public TestWithBrowserView {
+ public:
+ void SetUp() override;
+ BrowserRootView& browser_root_view() {
+ auto* res =
+ static_cast<BrowserRootView*>(browser_view()->frame()->GetRootView());
+ CHECK(res);
+ return *res;
+ }
+
+ content::WebContents& active_webcontents() {
+ auto* res = browser()->tab_strip_model()->GetActiveWebContents();
+ CHECK(res);
+ return *res;
+ }
+
+ int DropAtTheEndOfTabStrip(const ui::OSExchangeData& drop_data,
+ int drag_type);
+};
+
+void BrowserRootViewTest::SetUp() {
+ TestWithBrowserView::SetUp();
+ profile()->SetGuestSession(true); // avoiding dealing with avatar images
+ AddTab(browser(), GURL(url::kAboutBlankURL));
+}
+
+int BrowserRootViewTest::DropAtTheEndOfTabStrip(
+ const ui::OSExchangeData& drop_data,
+ int drag_type) {
+ gfx::Rect new_tab_batton_bounds =
+ browser_view()->tabstrip()->GetNewTabButtonBounds();
+ ui::DropTargetEvent drop_event(drop_data, new_tab_batton_bounds.origin(),
+ new_tab_batton_bounds.origin(), drag_type);
+ browser_root_view().OnDragEntered(drop_event);
+ return browser_root_view().OnPerformDrop(drop_event);
+}
+
+TEST_F(BrowserRootViewTest, DragAndDropText) {
+ ui::OSExchangeData drop_data;
+ drop_data.SetString(base::ASCIIToUTF16("query"));
+ EXPECT_TRUE(browser_root_view().CanDrop(drop_data));
+ EXPECT_EQ(DropAtTheEndOfTabStrip(drop_data, ui::DragDropTypes::DRAG_MOVE),
+ ui::DragDropTypes::DRAG_MOVE);
+ CommitPendingLoad(&active_webcontents().GetController());
+ EXPECT_EQ(active_webcontents().GetLastCommittedURL().host(),
+ kSearchEngineHost);
+}
+
+TEST_F(BrowserRootViewTest, DragAndDropTextParsableAsURL) {
+ ui::OSExchangeData drop_data;
+ drop_data.SetString(base::ASCIIToUTF16(kVeryUnlikelyUrl));
+ EXPECT_TRUE(browser_root_view().CanDrop(drop_data));
+ EXPECT_EQ(DropAtTheEndOfTabStrip(drop_data, ui::DragDropTypes::DRAG_MOVE),
+ ui::DragDropTypes::DRAG_MOVE);
+ CommitPendingLoad(&active_webcontents().GetController());
+ EXPECT_EQ(active_webcontents().GetLastCommittedURL().host(),
+ kSearchEngineHost);
+}
+
+TEST_F(BrowserRootViewTest, DragAndDropURL) {
+ ui::OSExchangeData drop_data;
+ GURL url(kVeryUnlikelyUrl);
+ drop_data.SetURL(url, {});
+ EXPECT_TRUE(browser_root_view().CanDrop(drop_data));
+ EXPECT_EQ(DropAtTheEndOfTabStrip(drop_data, ui::DragDropTypes::DRAG_MOVE),
+ ui::DragDropTypes::DRAG_MOVE);
+ CommitPendingLoad(&active_webcontents().GetController());
+ EXPECT_EQ(active_webcontents().GetLastCommittedURL(), url);
+}
« no previous file with comments | « no previous file | chrome/browser/ui/views/tabs/tab_strip.cc » ('j') | chrome/browser/ui/views/tabs/tab_strip.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698