| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <cstdio> | 5 #include <cstdio> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/process_util.h" | 12 #include "base/process_util.h" |
| 13 #include "base/shared_memory.h" | 13 #include "base/shared_memory.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "chrome/browser/visitedlink/visitedlink_event_listener.h" | 15 #include "chrome/browser/visitedlink/visitedlink_event_listener.h" |
| 16 #include "chrome/browser/visitedlink/visitedlink_master.h" | 16 #include "chrome/browser/visitedlink/visitedlink_master.h" |
| 17 #include "chrome/common/render_messages.h" | 17 #include "chrome/common/render_messages.h" |
| 18 #include "chrome/renderer/visitedlink_slave.h" | 18 #include "chrome/renderer/visitedlink_slave.h" |
| 19 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 19 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 20 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
| 21 #include "content/browser/renderer_host/browser_render_process_host.h" | 21 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 22 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
| 23 #include "content/public/browser/notification_types.h" | 23 #include "content/public/browser/notification_types.h" |
| 24 #include "content/test/test_browser_thread.h" | 24 #include "content/test/test_browser_thread.h" |
| 25 #include "googleurl/src/gurl.h" | 25 #include "googleurl/src/gurl.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 27 |
| 28 using content::BrowserThread; | 28 using content::BrowserThread; |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 int reset_event_count() const { return reset_event_count_; } | 488 int reset_event_count() const { return reset_event_count_; } |
| 489 | 489 |
| 490 private: | 490 private: |
| 491 int add_count_; | 491 int add_count_; |
| 492 int add_event_count_; | 492 int add_event_count_; |
| 493 int reset_event_count_; | 493 int reset_event_count_; |
| 494 scoped_ptr<VisitedLinkEventListener> event_listener_; | 494 scoped_ptr<VisitedLinkEventListener> event_listener_; |
| 495 scoped_ptr<VisitedLinkMaster> visited_link_master_; | 495 scoped_ptr<VisitedLinkMaster> visited_link_master_; |
| 496 }; | 496 }; |
| 497 | 497 |
| 498 // Stub out as little as possible, borrowing from BrowserRenderProcessHost. | 498 // Stub out as little as possible, borrowing from RenderProcessHost. |
| 499 class VisitRelayingRenderProcessHost : public BrowserRenderProcessHost { | 499 class VisitRelayingRenderProcessHost : public RenderProcessHostImpl { |
| 500 public: | 500 public: |
| 501 explicit VisitRelayingRenderProcessHost( | 501 explicit VisitRelayingRenderProcessHost( |
| 502 content::BrowserContext* browser_context) | 502 content::BrowserContext* browser_context) |
| 503 : BrowserRenderProcessHost(browser_context) { | 503 : RenderProcessHostImpl(browser_context) { |
| 504 content::NotificationService::current()->Notify( | 504 content::NotificationService::current()->Notify( |
| 505 content::NOTIFICATION_RENDERER_PROCESS_CREATED, | 505 content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
| 506 content::Source<RenderProcessHost>(this), | 506 content::Source<RenderProcessHost>(this), |
| 507 content::NotificationService::NoDetails()); | 507 content::NotificationService::NoDetails()); |
| 508 } | 508 } |
| 509 virtual ~VisitRelayingRenderProcessHost() { | 509 virtual ~VisitRelayingRenderProcessHost() { |
| 510 content::NotificationService::current()->Notify( | 510 content::NotificationService::current()->Notify( |
| 511 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 511 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 512 content::Source<RenderProcessHost>(this), | 512 content::Source<content::RenderProcessHost>(this), |
| 513 content::NotificationService::NoDetails()); | 513 content::NotificationService::NoDetails()); |
| 514 } | 514 } |
| 515 | 515 |
| 516 virtual bool Init(bool is_accessibility_enabled) { | 516 virtual bool Init(bool is_accessibility_enabled) { |
| 517 return true; | 517 return true; |
| 518 } | 518 } |
| 519 | 519 |
| 520 virtual void CancelResourceRequests(int render_widget_id) { | 520 virtual void CancelResourceRequests(int render_widget_id) { |
| 521 } | 521 } |
| 522 | 522 |
| 523 virtual void CrossSiteSwapOutACK(const ViewMsg_SwapOut_Params& params) { | 523 virtual void CrossSiteSwapOutACK(const ViewMsg_SwapOut_Params& params) { |
| 524 } | 524 } |
| 525 | 525 |
| 526 virtual bool WaitForPaintMsg(int render_widget_id, | 526 virtual bool WaitForPaintMsg(int render_widget_id, |
| 527 const base::TimeDelta& max_delay, | 527 const base::TimeDelta& max_delay, |
| 528 IPC::Message* msg) { | 528 IPC::Message* msg) { |
| 529 return false; | 529 return false; |
| 530 } | 530 } |
| 531 | 531 |
| 532 virtual bool Send(IPC::Message* msg) { | 532 virtual bool Send(IPC::Message* msg) { |
| 533 VisitCountingProfile* counting_profile = | 533 VisitCountingProfile* counting_profile = |
| 534 static_cast<VisitCountingProfile*>( | 534 static_cast<VisitCountingProfile*>( |
| 535 Profile::FromBrowserContext(browser_context())); | 535 Profile::FromBrowserContext(GetBrowserContext())); |
| 536 | 536 |
| 537 if (msg->type() == ChromeViewMsg_VisitedLink_Add::ID) { | 537 if (msg->type() == ChromeViewMsg_VisitedLink_Add::ID) { |
| 538 void* iter = NULL; | 538 void* iter = NULL; |
| 539 std::vector<uint64> fingerprints; | 539 std::vector<uint64> fingerprints; |
| 540 CHECK(IPC::ReadParam(msg, &iter, &fingerprints)); | 540 CHECK(IPC::ReadParam(msg, &iter, &fingerprints)); |
| 541 counting_profile->CountAddEvent(fingerprints.size()); | 541 counting_profile->CountAddEvent(fingerprints.size()); |
| 542 } else if (msg->type() == ChromeViewMsg_VisitedLink_Reset::ID) { | 542 } else if (msg->type() == ChromeViewMsg_VisitedLink_Reset::ID) { |
| 543 counting_profile->CountResetEvent(); | 543 counting_profile->CountResetEvent(); |
| 544 } | 544 } |
| 545 | 545 |
| 546 delete msg; | 546 delete msg; |
| 547 return true; | 547 return true; |
| 548 } | 548 } |
| 549 | 549 |
| 550 virtual void SetBackgrounded(bool backgrounded) { | 550 virtual void SetBackgrounded(bool backgrounded) { |
| 551 backgrounded_ = backgrounded; | 551 backgrounded_ = backgrounded; |
| 552 } | 552 } |
| 553 | 553 |
| 554 private: | 554 private: |
| 555 DISALLOW_COPY_AND_ASSIGN(VisitRelayingRenderProcessHost); | 555 DISALLOW_COPY_AND_ASSIGN(VisitRelayingRenderProcessHost); |
| 556 }; | 556 }; |
| 557 | 557 |
| 558 class VisitedLinkRenderProcessHostFactory | 558 class VisitedLinkRenderProcessHostFactory |
| 559 : public RenderProcessHostFactory { | 559 : public content::RenderProcessHostFactory { |
| 560 public: | 560 public: |
| 561 VisitedLinkRenderProcessHostFactory() | 561 VisitedLinkRenderProcessHostFactory() |
| 562 : RenderProcessHostFactory() {} | 562 : content::RenderProcessHostFactory() {} |
| 563 virtual RenderProcessHost* CreateRenderProcessHost( | 563 virtual content::RenderProcessHost* CreateRenderProcessHost( |
| 564 content::BrowserContext* browser_context) const OVERRIDE { | 564 content::BrowserContext* browser_context) const OVERRIDE { |
| 565 return new VisitRelayingRenderProcessHost(browser_context); | 565 return new VisitRelayingRenderProcessHost(browser_context); |
| 566 } | 566 } |
| 567 | 567 |
| 568 private: | 568 private: |
| 569 | 569 |
| 570 DISALLOW_COPY_AND_ASSIGN(VisitedLinkRenderProcessHostFactory); | 570 DISALLOW_COPY_AND_ASSIGN(VisitedLinkRenderProcessHostFactory); |
| 571 }; | 571 }; |
| 572 | 572 |
| 573 class VisitedLinkEventsTest : public ChromeRenderViewHostTestHarness { | 573 class VisitedLinkEventsTest : public ChromeRenderViewHostTestHarness { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 EXPECT_EQ(1, profile()->add_event_count()); | 720 EXPECT_EQ(1, profile()->add_event_count()); |
| 721 EXPECT_EQ(0, profile()->reset_event_count()); | 721 EXPECT_EQ(0, profile()->reset_event_count()); |
| 722 | 722 |
| 723 // Activate the tab. | 723 // Activate the tab. |
| 724 rvh()->WasRestored(); | 724 rvh()->WasRestored(); |
| 725 | 725 |
| 726 // We should have only one more reset event. | 726 // We should have only one more reset event. |
| 727 EXPECT_EQ(1, profile()->add_event_count()); | 727 EXPECT_EQ(1, profile()->add_event_count()); |
| 728 EXPECT_EQ(1, profile()->reset_event_count()); | 728 EXPECT_EQ(1, profile()->reset_event_count()); |
| 729 } | 729 } |
| OLD | NEW |