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/search_ipc_router.h" | 5 #include "chrome/browser/ui/search/search_ipc_router.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 MOCK_METHOD1(OnDeleteMostVisitedItem, void(const GURL& url)); | 51 MOCK_METHOD1(OnDeleteMostVisitedItem, void(const GURL& url)); |
52 MOCK_METHOD1(OnUndoMostVisitedDeletion, void(const GURL& url)); | 52 MOCK_METHOD1(OnUndoMostVisitedDeletion, void(const GURL& url)); |
53 MOCK_METHOD0(OnUndoAllMostVisitedDeletions, void()); | 53 MOCK_METHOD0(OnUndoAllMostVisitedDeletions, void()); |
54 MOCK_METHOD1(OnLogEvent, void(NTPLoggingEventType event)); | 54 MOCK_METHOD1(OnLogEvent, void(NTPLoggingEventType event)); |
55 MOCK_METHOD2(OnLogMostVisitedImpression, | 55 MOCK_METHOD2(OnLogMostVisitedImpression, |
56 void(int position, const base::string16& provider)); | 56 void(int position, const base::string16& provider)); |
57 MOCK_METHOD2(OnLogMostVisitedNavigation, | 57 MOCK_METHOD2(OnLogMostVisitedNavigation, |
58 void(int position, const base::string16& provider)); | 58 void(int position, const base::string16& provider)); |
59 MOCK_METHOD1(PasteIntoOmnibox, void(const base::string16&)); | 59 MOCK_METHOD1(PasteIntoOmnibox, void(const base::string16&)); |
60 MOCK_METHOD1(OnChromeIdentityCheck, void(const base::string16& identity)); | 60 MOCK_METHOD1(OnChromeIdentityCheck, void(const base::string16& identity)); |
61 MOCK_METHOD0(OnHistorySyncCheck, void()); | |
61 }; | 62 }; |
62 | 63 |
63 class MockSearchIPCRouterPolicy : public SearchIPCRouter::Policy { | 64 class MockSearchIPCRouterPolicy : public SearchIPCRouter::Policy { |
64 public: | 65 public: |
65 virtual ~MockSearchIPCRouterPolicy() {} | 66 virtual ~MockSearchIPCRouterPolicy() {} |
66 | 67 |
67 MOCK_METHOD0(ShouldProcessSetVoiceSearchSupport, bool()); | 68 MOCK_METHOD0(ShouldProcessSetVoiceSearchSupport, bool()); |
68 MOCK_METHOD1(ShouldProcessFocusOmnibox, bool(bool)); | 69 MOCK_METHOD1(ShouldProcessFocusOmnibox, bool(bool)); |
69 MOCK_METHOD1(ShouldProcessNavigateToURL, bool(bool)); | 70 MOCK_METHOD1(ShouldProcessNavigateToURL, bool(bool)); |
70 MOCK_METHOD0(ShouldProcessDeleteMostVisitedItem, bool()); | 71 MOCK_METHOD0(ShouldProcessDeleteMostVisitedItem, bool()); |
71 MOCK_METHOD0(ShouldProcessUndoMostVisitedDeletion, bool()); | 72 MOCK_METHOD0(ShouldProcessUndoMostVisitedDeletion, bool()); |
72 MOCK_METHOD0(ShouldProcessUndoAllMostVisitedDeletions, bool()); | 73 MOCK_METHOD0(ShouldProcessUndoAllMostVisitedDeletions, bool()); |
73 MOCK_METHOD0(ShouldProcessLogEvent, bool()); | 74 MOCK_METHOD0(ShouldProcessLogEvent, bool()); |
74 MOCK_METHOD1(ShouldProcessPasteIntoOmnibox, bool(bool)); | 75 MOCK_METHOD1(ShouldProcessPasteIntoOmnibox, bool(bool)); |
75 MOCK_METHOD0(ShouldProcessChromeIdentityCheck, bool()); | 76 MOCK_METHOD0(ShouldProcessChromeIdentityCheck, bool()); |
77 MOCK_METHOD0(ShouldProcessHistorySyncCheck, bool()); | |
76 MOCK_METHOD0(ShouldSendSetPromoInformation, bool()); | 78 MOCK_METHOD0(ShouldSendSetPromoInformation, bool()); |
77 MOCK_METHOD0(ShouldSendSetDisplayInstantResults, bool()); | 79 MOCK_METHOD0(ShouldSendSetDisplayInstantResults, bool()); |
78 MOCK_METHOD0(ShouldSendSetSuggestionToPrefetch, bool()); | 80 MOCK_METHOD0(ShouldSendSetSuggestionToPrefetch, bool()); |
79 MOCK_METHOD0(ShouldSendSetOmniboxStartMargin, bool()); | 81 MOCK_METHOD0(ShouldSendSetOmniboxStartMargin, bool()); |
80 MOCK_METHOD1(ShouldSendSetInputInProgress, bool(bool)); | 82 MOCK_METHOD1(ShouldSendSetInputInProgress, bool(bool)); |
81 MOCK_METHOD0(ShouldSendOmniboxFocusChanged, bool()); | 83 MOCK_METHOD0(ShouldSendOmniboxFocusChanged, bool()); |
82 MOCK_METHOD0(ShouldSendMostVisitedItems, bool()); | 84 MOCK_METHOD0(ShouldSendMostVisitedItems, bool()); |
83 MOCK_METHOD0(ShouldSendThemeBackgroundInfo, bool()); | 85 MOCK_METHOD0(ShouldSendThemeBackgroundInfo, bool()); |
84 MOCK_METHOD0(ShouldSendToggleVoiceSearch, bool()); | 86 MOCK_METHOD0(ShouldSendToggleVoiceSearch, bool()); |
85 MOCK_METHOD0(ShouldSubmitQuery, bool()); | 87 MOCK_METHOD0(ShouldSubmitQuery, bool()); |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 EXPECT_CALL(*mock_delegate(), OnChromeIdentityCheck(test_identity)).Times(0); | 442 EXPECT_CALL(*mock_delegate(), OnChromeIdentityCheck(test_identity)).Times(0); |
441 EXPECT_CALL(*policy, ShouldProcessChromeIdentityCheck()).Times(1) | 443 EXPECT_CALL(*policy, ShouldProcessChromeIdentityCheck()).Times(1) |
442 .WillOnce(testing::Return(false)); | 444 .WillOnce(testing::Return(false)); |
443 | 445 |
444 content::WebContents* contents = web_contents(); | 446 content::WebContents* contents = web_contents(); |
445 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_ChromeIdentityCheck( | 447 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_ChromeIdentityCheck( |
446 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), test_identity)); | 448 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), test_identity)); |
447 OnMessageReceived(*message); | 449 OnMessageReceived(*message); |
448 } | 450 } |
449 | 451 |
452 TEST_F(SearchIPCRouterTest, ProcessHistorySyncCheckMsg) { | |
453 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); | |
454 SetupMockDelegateAndPolicy(); | |
455 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); | |
456 EXPECT_CALL(*mock_delegate(), OnHistorySyncCheck()).Times(1); | |
457 EXPECT_CALL(*policy, ShouldProcessHistorySyncCheck()).Times(1) | |
458 .WillOnce(testing::Return(true)); | |
459 | |
460 content::WebContents* contents = web_contents(); | |
461 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_HistorySyncCheck( | |
dcheng
2014/11/12 21:40:47
Nit: Can't this (and line 477) just be stack alloc
beaudoin
2014/11/20 22:58:26
Just copied what was everywhere else. I've updated
dcheng
2014/11/21 20:50:32
Sorry, you should have just pushed back on this. I
beaudoin
2014/11/21 21:16:36
I agreed with you and figured if no one ever did i
| |
462 contents->GetRoutingID(), GetSearchIPCRouterSeqNo())); | |
463 OnMessageReceived(*message); | |
464 } | |
465 | |
466 TEST_F(SearchIPCRouterTest, IgnoreHistorySyncCheckMsg) { | |
467 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); | |
468 SetupMockDelegateAndPolicy(); | |
469 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); | |
470 | |
471 EXPECT_CALL(*mock_delegate(), OnHistorySyncCheck()).Times(0); | |
472 EXPECT_CALL(*policy, ShouldProcessHistorySyncCheck()).Times(1) | |
473 .WillOnce(testing::Return(false)); | |
474 | |
475 content::WebContents* contents = web_contents(); | |
476 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_HistorySyncCheck( | |
477 contents->GetRoutingID(), GetSearchIPCRouterSeqNo())); | |
478 OnMessageReceived(*message); | |
479 } | |
480 | |
450 TEST_F(SearchIPCRouterTest, ProcessDeleteMostVisitedItemMsg) { | 481 TEST_F(SearchIPCRouterTest, ProcessDeleteMostVisitedItemMsg) { |
451 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); | 482 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); |
452 SetupMockDelegateAndPolicy(); | 483 SetupMockDelegateAndPolicy(); |
453 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); | 484 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); |
454 GURL item_url("www.foo.com"); | 485 GURL item_url("www.foo.com"); |
455 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(1); | 486 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(1); |
456 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(1) | 487 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(1) |
457 .WillOnce(testing::Return(true)); | 488 .WillOnce(testing::Return(true)); |
458 | 489 |
459 content::WebContents* contents = web_contents(); | 490 content::WebContents* contents = web_contents(); |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
903 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); | 934 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); |
904 SetupMockDelegateAndPolicy(); | 935 SetupMockDelegateAndPolicy(); |
905 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); | 936 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); |
906 EXPECT_CALL(*policy, ShouldSendToggleVoiceSearch()).Times(1) | 937 EXPECT_CALL(*policy, ShouldSendToggleVoiceSearch()).Times(1) |
907 .WillOnce(testing::Return(false)); | 938 .WillOnce(testing::Return(false)); |
908 | 939 |
909 process()->sink().ClearMessages(); | 940 process()->sink().ClearMessages(); |
910 GetSearchIPCRouter().ToggleVoiceSearch(); | 941 GetSearchIPCRouter().ToggleVoiceSearch(); |
911 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxToggleVoiceSearch::ID)); | 942 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxToggleVoiceSearch::ID)); |
912 } | 943 } |
OLD | NEW |