| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/search/instant_page.h" | 5 #include "chrome/browser/ui/search/instant_page.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "chrome/common/render_messages.h" | 8 #include "chrome/common/render_messages.h" |
| 9 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
| 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 MOCK_METHOD0(LogDropdownShown, void()); | 42 MOCK_METHOD0(LogDropdownShown, void()); |
| 43 MOCK_METHOD2(FocusOmnibox, | 43 MOCK_METHOD2(FocusOmnibox, |
| 44 void(const content::WebContents* contents, | 44 void(const content::WebContents* contents, |
| 45 OmniboxFocusState state)); | 45 OmniboxFocusState state)); |
| 46 MOCK_METHOD5(NavigateToURL, | 46 MOCK_METHOD5(NavigateToURL, |
| 47 void(const content::WebContents* contents, | 47 void(const content::WebContents* contents, |
| 48 const GURL& url, | 48 const GURL& url, |
| 49 content::PageTransition transition, | 49 content::PageTransition transition, |
| 50 WindowOpenDisposition disposition, | 50 WindowOpenDisposition disposition, |
| 51 bool is_search_type)); | 51 bool is_search_type)); |
| 52 MOCK_METHOD1(DeleteMostVisitedItem, | 52 MOCK_METHOD1(DeleteMostVisitedItem, void(const GURL& url)); |
| 53 void(InstantRestrictedID most_visited_item_id)); | 53 MOCK_METHOD1(UndoMostVisitedDeletion, void(const GURL& url)); |
| 54 MOCK_METHOD1(UndoMostVisitedDeletion, | |
| 55 void(InstantRestrictedID most_visited_item_id)); | |
| 56 MOCK_METHOD0(UndoAllMostVisitedDeletions, void()); | 54 MOCK_METHOD0(UndoAllMostVisitedDeletions, void()); |
| 57 MOCK_METHOD1(InstantPageLoadFailed, void(content::WebContents* contents)); | 55 MOCK_METHOD1(InstantPageLoadFailed, void(content::WebContents* contents)); |
| 58 }; | 56 }; |
| 59 | 57 |
| 60 class FakePage : public InstantPage { | 58 class FakePage : public InstantPage { |
| 61 public: | 59 public: |
| 62 FakePage(Delegate* delegate, const std::string& instant_url) | 60 FakePage(Delegate* delegate, const std::string& instant_url) |
| 63 : InstantPage(delegate, instant_url) { | 61 : InstantPage(delegate, instant_url) { |
| 64 } | 62 } |
| 65 virtual ~FakePage() { | 63 virtual ~FakePage() { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 page->SetContents(web_contents()); | 104 page->SetContents(web_contents()); |
| 107 NavigateAndCommit(GURL("http://example.com/")); | 105 NavigateAndCommit(GURL("http://example.com/")); |
| 108 EXPECT_FALSE(page->IsLocal()); | 106 EXPECT_FALSE(page->IsLocal()); |
| 109 process()->sink().ClearMessages(); | 107 process()->sink().ClearMessages(); |
| 110 page->DetermineIfPageSupportsInstant(); | 108 page->DetermineIfPageSupportsInstant(); |
| 111 const IPC::Message* message = process()->sink().GetFirstMessageMatching( | 109 const IPC::Message* message = process()->sink().GetFirstMessageMatching( |
| 112 ChromeViewMsg_DetermineIfPageSupportsInstant::ID); | 110 ChromeViewMsg_DetermineIfPageSupportsInstant::ID); |
| 113 ASSERT_TRUE(message != NULL); | 111 ASSERT_TRUE(message != NULL); |
| 114 EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id()); | 112 EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id()); |
| 115 } | 113 } |
| 114 |
| 115 TEST_F(InstantPageTest, DispatchRequestToDeleteMostVisitedItem) { |
| 116 page.reset(new FakePage(&delegate, "")); |
| 117 page->SetContents(web_contents()); |
| 118 GURL item_url("www.foo.com"); |
| 119 EXPECT_CALL(delegate, DeleteMostVisitedItem(item_url)).Times(1); |
| 120 EXPECT_TRUE(page->OnMessageReceived( |
| 121 ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(rvh()->GetRoutingID(), |
| 122 item_url))); |
| 123 } |
| 124 |
| 125 TEST_F(InstantPageTest, DispatchRequestToUndoMostVisitedDeletion) { |
| 126 page.reset(new FakePage(&delegate, "")); |
| 127 page->SetContents(web_contents()); |
| 128 GURL item_url("www.foo.com"); |
| 129 EXPECT_CALL(delegate, UndoMostVisitedDeletion(item_url)).Times(1); |
| 130 EXPECT_TRUE(page->OnMessageReceived( |
| 131 ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(rvh()->GetRoutingID(), |
| 132 item_url))); |
| 133 } |
| 134 |
| 135 TEST_F(InstantPageTest, DispatchRequestToUndoAllMostVisitedDeletions) { |
| 136 page.reset(new FakePage(&delegate, "")); |
| 137 page->SetContents(web_contents()); |
| 138 EXPECT_CALL(delegate, UndoAllMostVisitedDeletions()).Times(1); |
| 139 EXPECT_TRUE(page->OnMessageReceived( |
| 140 ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( |
| 141 rvh()->GetRoutingID()))); |
| 142 } |
| OLD | NEW |