| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2016 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 "chrome/browser/ui/views/frame/browser_root_view.h" |
| 6 |
| 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 9 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 10 #include "chrome/browser/ui/views/frame/test_with_browser_view.h" |
| 11 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 12 #include "content/public/browser/web_contents.h" |
| 13 #include "ui/base/dragdrop/os_exchange_data.h" |
| 14 #include "url/gurl.h" |
| 15 #include "url/url_constants.h" |
| 16 |
| 17 constexpr char kSearchEngineHost[] = "www.google.com"; |
| 18 |
| 19 // This text is a valid url but it's very unlikely that user meant it to be used |
| 20 // as one. We ought to process it as query unless the only way to interpret it |
| 21 // is as url. |
| 22 constexpr char kVeryUnlikelyUrl[] = "query: abcd"; |
| 23 |
| 24 class BrowserRootViewTest : public TestWithBrowserView { |
| 25 public: |
| 26 void SetUp() override; |
| 27 BrowserRootView& browser_root_view() { |
| 28 auto* res = |
| 29 static_cast<BrowserRootView*>(browser_view()->frame()->GetRootView()); |
| 30 CHECK(res); |
| 31 return *res; |
| 32 } |
| 33 |
| 34 content::WebContents& active_webcontents() { |
| 35 auto* res = browser()->tab_strip_model()->GetActiveWebContents(); |
| 36 CHECK(res); |
| 37 return *res; |
| 38 } |
| 39 |
| 40 int DropAtTheEndOfTabStrip(const ui::OSExchangeData& drop_data, |
| 41 int drag_type); |
| 42 }; |
| 43 |
| 44 void BrowserRootViewTest::SetUp() { |
| 45 TestWithBrowserView::SetUp(); |
| 46 profile()->SetGuestSession(true); // avoiding dealing with avatar images |
| 47 AddTab(browser(), GURL(url::kAboutBlankURL)); |
| 48 } |
| 49 |
| 50 int BrowserRootViewTest::DropAtTheEndOfTabStrip( |
| 51 const ui::OSExchangeData& drop_data, |
| 52 int drag_type) { |
| 53 gfx::Rect new_tab_batton_bounds = |
| 54 browser_view()->tabstrip()->GetNewTabButtonBounds(); |
| 55 ui::DropTargetEvent drop_event(drop_data, new_tab_batton_bounds.origin(), |
| 56 new_tab_batton_bounds.origin(), drag_type); |
| 57 browser_root_view().OnDragEntered(drop_event); |
| 58 return browser_root_view().OnPerformDrop(drop_event); |
| 59 } |
| 60 |
| 61 TEST_F(BrowserRootViewTest, DragAndDropText) { |
| 62 ui::OSExchangeData drop_data; |
| 63 drop_data.SetString(base::ASCIIToUTF16("query")); |
| 64 EXPECT_TRUE(browser_root_view().CanDrop(drop_data)); |
| 65 EXPECT_EQ(DropAtTheEndOfTabStrip(drop_data, ui::DragDropTypes::DRAG_MOVE), |
| 66 ui::DragDropTypes::DRAG_MOVE); |
| 67 CommitPendingLoad(&active_webcontents().GetController()); |
| 68 EXPECT_EQ(active_webcontents().GetLastCommittedURL().host(), |
| 69 kSearchEngineHost); |
| 70 } |
| 71 |
| 72 TEST_F(BrowserRootViewTest, DragAndDropTextParsableAsURL) { |
| 73 ui::OSExchangeData drop_data; |
| 74 drop_data.SetString(base::ASCIIToUTF16(kVeryUnlikelyUrl)); |
| 75 EXPECT_TRUE(browser_root_view().CanDrop(drop_data)); |
| 76 EXPECT_EQ(DropAtTheEndOfTabStrip(drop_data, ui::DragDropTypes::DRAG_MOVE), |
| 77 ui::DragDropTypes::DRAG_MOVE); |
| 78 CommitPendingLoad(&active_webcontents().GetController()); |
| 79 EXPECT_EQ(active_webcontents().GetLastCommittedURL().host(), |
| 80 kSearchEngineHost); |
| 81 } |
| 82 |
| 83 TEST_F(BrowserRootViewTest, DragAndDropURL) { |
| 84 ui::OSExchangeData drop_data; |
| 85 GURL url(kVeryUnlikelyUrl); |
| 86 drop_data.SetURL(url, {}); |
| 87 EXPECT_TRUE(browser_root_view().CanDrop(drop_data)); |
| 88 EXPECT_EQ(DropAtTheEndOfTabStrip(drop_data, ui::DragDropTypes::DRAG_MOVE), |
| 89 ui::DragDropTypes::DRAG_MOVE); |
| 90 CommitPendingLoad(&active_webcontents().GetController()); |
| 91 EXPECT_EQ(active_webcontents().GetLastCommittedURL(), url); |
| 92 } |
| OLD | NEW |