| OLD | NEW | 
|    1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |    1 // Copyright (c) 2012 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 "base/file_util.h" |    5 #include "base/file_util.h" | 
|    6 #include "base/json/json_file_value_serializer.h" |    6 #include "base/json/json_file_value_serializer.h" | 
|    7 #include "base/message_loop.h" |    7 #include "base/message_loop.h" | 
|    8 #include "base/path_service.h" |    8 #include "base/path_service.h" | 
|    9 #include "base/scoped_temp_dir.h" |    9 #include "base/scoped_temp_dir.h" | 
|   10 #include "base/utf_string_conversions.h" |   10 #include "base/utf_string_conversions.h" | 
|   11 #include "chrome/browser/extensions/test_extension_service.h" |   11 #include "chrome/browser/extensions/test_extension_service.h" | 
 |   12 #include "chrome/browser/intents/default_web_intent_service.h" | 
|   12 #include "chrome/browser/intents/web_intents_registry.h" |   13 #include "chrome/browser/intents/web_intents_registry.h" | 
|   13 #include "chrome/browser/webdata/web_data_service.h" |   14 #include "chrome/browser/webdata/web_data_service.h" | 
|   14 #include "chrome/common/chrome_paths.h" |   15 #include "chrome/common/chrome_paths.h" | 
|   15 #include "chrome/common/extensions/extension_set.h" |   16 #include "chrome/common/extensions/extension_set.h" | 
|   16 #include "content/test/test_browser_thread.h" |   17 #include "content/test/test_browser_thread.h" | 
|   17 #include "testing/gmock/include/gmock/gmock.h" |   18 #include "testing/gmock/include/gmock/gmock.h" | 
|   18 #include "testing/gtest/include/gtest/gtest.h" |   19 #include "testing/gtest/include/gtest/gtest.h" | 
|   19  |   20  | 
|   20 using content::BrowserThread; |   21 using content::BrowserThread; | 
|   21 using webkit_glue::WebIntentServiceData; |   22 using webkit_glue::WebIntentServiceData; | 
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  120    virtual void OnIntentsQueryDone( |  121    virtual void OnIntentsQueryDone( | 
|  121        WebIntentsRegistry::QueryID id, |  122        WebIntentsRegistry::QueryID id, | 
|  122        const std::vector<webkit_glue::WebIntentServiceData>& services) { |  123        const std::vector<webkit_glue::WebIntentServiceData>& services) { | 
|  123      DCHECK(id == expected_id_); |  124      DCHECK(id == expected_id_); | 
|  124      services_ = services; |  125      services_ = services; | 
|  125  |  126  | 
|  126      DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |  127      DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
|  127      MessageLoop::current()->Quit(); |  128      MessageLoop::current()->Quit(); | 
|  128    } |  129    } | 
|  129  |  130  | 
 |  131    virtual void OnIntentsDefaultsQueryDone( | 
 |  132        WebIntentsRegistry::QueryID id, | 
 |  133        const DefaultWebIntentService& default_service) { | 
 |  134      DCHECK(id == expected_id_); | 
 |  135      default_ = default_service; | 
 |  136  | 
 |  137      DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
 |  138      MessageLoop::current()->Quit(); | 
 |  139    } | 
 |  140  | 
|  130    // Wait for the UI message loop to terminate - happens when OnIntesQueryDone |  141    // Wait for the UI message loop to terminate - happens when OnIntesQueryDone | 
|  131    // is invoked. |  142    // is invoked. | 
|  132    void WaitForData() { |  143    void WaitForData() { | 
|  133      DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |  144      DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
|  134      MessageLoop::current()->Run(); |  145      MessageLoop::current()->Run(); | 
|  135    } |  146    } | 
|  136  |  147  | 
|  137    // QueryID callback is tied to. |  148    // QueryID callback is tied to. | 
|  138    WebIntentsRegistry::QueryID expected_id_; |  149    WebIntentsRegistry::QueryID expected_id_; | 
|  139  |  150  | 
|  140    // Result data from callback. |  151    // Result data from callback. | 
|  141    std::vector<webkit_glue::WebIntentServiceData> services_; |  152    std::vector<webkit_glue::WebIntentServiceData> services_; | 
 |  153  | 
 |  154    // Result default data from callback. | 
 |  155    DefaultWebIntentService default_; | 
|  142 }; |  156 }; | 
|  143  |  157  | 
|  144 TEST_F(WebIntentsRegistryTest, BasicTests) { |  158 TEST_F(WebIntentsRegistryTest, BasicTests) { | 
|  145   webkit_glue::WebIntentServiceData service; |  159   webkit_glue::WebIntentServiceData service; | 
|  146   service.service_url = GURL("http://google.com"); |  160   service.service_url = GURL("http://google.com"); | 
|  147   service.action = ASCIIToUTF16("share"); |  161   service.action = ASCIIToUTF16("share"); | 
|  148   service.type = ASCIIToUTF16("image/*"); |  162   service.type = ASCIIToUTF16("image/*"); | 
|  149   service.title = ASCIIToUTF16("Google's Sharing Service"); |  163   service.title = ASCIIToUTF16("Google's Sharing Service"); | 
|  150  |  164  | 
|  151   registry_.RegisterIntentService(service); |  165   registry_.RegisterIntentService(service); | 
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  320   consumer.expected_id_ = registry_.GetIntentServices( |  334   consumer.expected_id_ = registry_.GetIntentServices( | 
|  321       ASCIIToUTF16("http://webintents.org/share"), |  335       ASCIIToUTF16("http://webintents.org/share"), | 
|  322       ASCIIToUTF16("*"), &consumer); |  336       ASCIIToUTF16("*"), &consumer); | 
|  323   consumer.WaitForData(); |  337   consumer.WaitForData(); | 
|  324   ASSERT_EQ(4U, consumer.services_.size()); |  338   ASSERT_EQ(4U, consumer.services_.size()); | 
|  325   EXPECT_EQ(services[0], consumer.services_[0]); |  339   EXPECT_EQ(services[0], consumer.services_[0]); | 
|  326   EXPECT_EQ(services[1], consumer.services_[1]); |  340   EXPECT_EQ(services[1], consumer.services_[1]); | 
|  327   EXPECT_EQ(services[2], consumer.services_[2]); |  341   EXPECT_EQ(services[2], consumer.services_[2]); | 
|  328   EXPECT_EQ(services[3], consumer.services_[3]); |  342   EXPECT_EQ(services[3], consumer.services_[3]); | 
|  329 } |  343 } | 
 |  344  | 
 |  345 TEST_F(WebIntentsRegistryTest, TestGetDefaults) { | 
 |  346   DefaultWebIntentService default_service; | 
 |  347   default_service.action = ASCIIToUTF16("share"); | 
 |  348   default_service.type = ASCIIToUTF16("type/*"); | 
 |  349   // Values here are just dummies to test for preservation. | 
 |  350   default_service.user_date = 1; | 
 |  351   default_service.suppression = 4; | 
 |  352   default_service.service_url = "service_url"; | 
 |  353   registry_.RegisterDefaultIntentService(default_service); | 
 |  354  | 
 |  355   TestConsumer consumer; | 
 |  356  | 
 |  357   // Test we can retrieve default entries by action. | 
 |  358   consumer.expected_id_ = registry_.GetDefaultIntentService( | 
 |  359       ASCIIToUTF16("share"), | 
 |  360       ASCIIToUTF16("type/plain"), | 
 |  361       GURL("http://www.google.com/"), | 
 |  362       &consumer); | 
 |  363  | 
 |  364   consumer.WaitForData(); | 
 |  365  | 
 |  366   EXPECT_EQ("service_url", consumer.default_.service_url); | 
 |  367   EXPECT_EQ(1, consumer.default_.user_date); | 
 |  368   EXPECT_EQ(4, consumer.default_.suppression); | 
 |  369  | 
 |  370   // Test that no action match means we don't retrieve any | 
 |  371   // default entries. | 
 |  372   consumer.default_ = DefaultWebIntentService(); | 
 |  373   ASSERT_EQ("", consumer.default_.service_url); | 
 |  374   consumer.expected_id_ = registry_.GetDefaultIntentService( | 
 |  375       ASCIIToUTF16("no-share"), | 
 |  376       ASCIIToUTF16("type/plain"), | 
 |  377       GURL("http://www.google.com/"), | 
 |  378       &consumer); | 
 |  379  | 
 |  380   consumer.WaitForData(); | 
 |  381  | 
 |  382   EXPECT_EQ("", consumer.default_.service_url); | 
 |  383  | 
 |  384   // Test that no type match means we don't retrieve any | 
 |  385   // default entries (they get filtered out). | 
 |  386   consumer.default_ = DefaultWebIntentService(); | 
 |  387   ASSERT_EQ("", consumer.default_.service_url); | 
 |  388   consumer.expected_id_ = registry_.GetDefaultIntentService( | 
 |  389       ASCIIToUTF16("share"), | 
 |  390       ASCIIToUTF16("notype/plain"), | 
 |  391       GURL("http://www.google.com/"), | 
 |  392       &consumer); | 
 |  393  | 
 |  394   consumer.WaitForData(); | 
 |  395  | 
 |  396   EXPECT_EQ("", consumer.default_.service_url); | 
 |  397 } | 
| OLD | NEW |