| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "athena/activity/public/activity.h" | 5 #include "athena/activity/public/activity.h" |
| 6 #include "athena/test/chrome/athena_browsertest.h" | 6 #include "athena/test/chrome/athena_browsertest.h" |
| 7 #include "athena/test/chrome/test_util.h" | 7 #include "athena/test/chrome/test_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/extensions/tab_helper.h" | 9 #include "chrome/browser/extensions/tab_helper.h" |
| 10 #include "content/public/browser/notification_observer.h" | 10 #include "content/public/browser/notification_observer.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // Checks that the web activity helpers are created prior to the RenderView | 21 // Checks that the web activity helpers are created prior to the RenderView |
| 22 // being created. | 22 // being created. |
| 23 class HelpersCreatedChecker : public content::NotificationObserver { | 23 class HelpersCreatedChecker : public content::NotificationObserver { |
| 24 public: | 24 public: |
| 25 HelpersCreatedChecker() : helpers_created_prior_to_render_view_(true) { | 25 HelpersCreatedChecker() : helpers_created_prior_to_render_view_(true) { |
| 26 registrar_.Add(this, | 26 registrar_.Add(this, |
| 27 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, | 27 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
| 28 content::NotificationService::AllSources()); | 28 content::NotificationService::AllSources()); |
| 29 } | 29 } |
| 30 | 30 |
| 31 virtual ~HelpersCreatedChecker() { | 31 ~HelpersCreatedChecker() override {} |
| 32 } | |
| 33 | 32 |
| 34 // Returns true if WebActivity helpers were attached to the WebContents prior | 33 // Returns true if WebActivity helpers were attached to the WebContents prior |
| 35 // to the RenderView being created for the WebContents. | 34 // to the RenderView being created for the WebContents. |
| 36 bool HelpersCreatedPriorToRenderView() const { | 35 bool HelpersCreatedPriorToRenderView() const { |
| 37 return helpers_created_prior_to_render_view_; | 36 return helpers_created_prior_to_render_view_; |
| 38 } | 37 } |
| 39 | 38 |
| 40 private: | 39 private: |
| 41 // content::NotificationObserver: | 40 // content::NotificationObserver: |
| 42 virtual void Observe(int type, | 41 void Observe(int type, |
| 43 const content::NotificationSource& source, | 42 const content::NotificationSource& source, |
| 44 const content::NotificationDetails& details) override { | 43 const content::NotificationDetails& details) override { |
| 45 DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, | 44 DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
| 46 type); | 45 type); |
| 47 | 46 |
| 48 // Assume that all of the WebActivity helpers were created if the | 47 // Assume that all of the WebActivity helpers were created if the |
| 49 // extensions::TabHelper was created. | 48 // extensions::TabHelper was created. |
| 50 content::WebContents* web_contents = | 49 content::WebContents* web_contents = |
| 51 content::Source<content::WebContents>(source).ptr(); | 50 content::Source<content::WebContents>(source).ptr(); |
| 52 helpers_created_prior_to_render_view_ &= | 51 helpers_created_prior_to_render_view_ &= |
| 53 (extensions::TabHelper::FromWebContents(web_contents) != nullptr); | 52 (extensions::TabHelper::FromWebContents(web_contents) != nullptr); |
| 54 } | 53 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 83 activity->SetCurrentState(Activity::ACTIVITY_UNLOADED); | 82 activity->SetCurrentState(Activity::ACTIVITY_UNLOADED); |
| 84 activity->SetCurrentState(Activity::ACTIVITY_VISIBLE); | 83 activity->SetCurrentState(Activity::ACTIVITY_VISIBLE); |
| 85 | 84 |
| 86 content::WebContents* web_contents2 = activity->GetWebContents(); | 85 content::WebContents* web_contents2 = activity->GetWebContents(); |
| 87 EXPECT_NE(web_contents1, web_contents2); | 86 EXPECT_NE(web_contents1, web_contents2); |
| 88 EXPECT_TRUE(web_contents2->GetRenderViewHost()->IsRenderViewLive()); | 87 EXPECT_TRUE(web_contents2->GetRenderViewHost()->IsRenderViewLive()); |
| 89 EXPECT_TRUE(checker.HelpersCreatedPriorToRenderView()); | 88 EXPECT_TRUE(checker.HelpersCreatedPriorToRenderView()); |
| 90 } | 89 } |
| 91 | 90 |
| 92 } // namespace athena | 91 } // namespace athena |
| OLD | NEW |