| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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/extensions/extension_tab_util.h" |
| 6 |
| 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" |
| 9 #include "chrome/common/extensions/api/tabs.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace extensions { |
| 13 |
| 14 namespace { |
| 15 |
| 16 const char kCustomUrl[] = "www.example.com/foo?bar=baz"; |
| 17 |
| 18 class ExtensionTabUtilTestDelegate : public ExtensionTabUtil::Delegate { |
| 19 public: |
| 20 ExtensionTabUtilTestDelegate() {} |
| 21 ~ExtensionTabUtilTestDelegate() override {} |
| 22 |
| 23 // ExtensionTabUtil::Delegate |
| 24 void ScrubTabForExtension(const Extension* extension, |
| 25 content::WebContents* contents, |
| 26 api::tabs::Tab* tab) override { |
| 27 tab->url.reset(new std::string(kCustomUrl)); |
| 28 } |
| 29 |
| 30 private: |
| 31 DISALLOW_COPY_AND_ASSIGN(ExtensionTabUtilTestDelegate); |
| 32 }; |
| 33 |
| 34 } // namespace |
| 35 |
| 36 // Test that the custom ScrubTabForExtension delegate works - in this test it |
| 37 // sets URL to a custom string. |
| 38 TEST(ExtensionTabUtilTest, Delegate) { |
| 39 auto test_delegate = base::MakeUnique<ExtensionTabUtilTestDelegate>(); |
| 40 ExtensionTabUtil::SetPlatformDelegate(test_delegate.get()); |
| 41 |
| 42 api::tabs::Tab tab; |
| 43 ExtensionTabUtil::ScrubTabForExtension(nullptr, nullptr, &tab); |
| 44 EXPECT_EQ(kCustomUrl, *tab.url); |
| 45 |
| 46 // Unset the delegate. |
| 47 ExtensionTabUtil::SetPlatformDelegate(nullptr); |
| 48 } |
| 49 |
| 50 } // namespace extensions |
| OLD | NEW |