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 3 // found in the LICENSE file. 4 5 #include <string> 6 7 #include "base/memory/scoped_ptr.h" 8 #include "base/strings/utf_string_conversions.h" 9 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" 10 #include "chrome/browser/extensions/api/activity_log_private/activity_log_private_api.h" 11 #include "testing/gtest/include/gtest/gtest.h" 12 13 namespace { 14 15 const char kExtensionId[] = "extensionid"; 16 const char kApiCall[] = "api.call"; 17 const char kArgs[] = "[\"hello\",\"world\"]"; 18 19 } // extensions 20 21 namespace extensions { 22 23 using api::activity_log_private::ExtensionActivity; 24 25 typedef testing::Test ActivityLogApiUnitTest; 26 27 TEST_F(ActivityLogApiUnitTest, ConvertChromeApiAction) { 28 scoped_ptr<base::ListValue> args(new base::ListValue()); 29 args->Set(0, new base::StringValue("hello")); 30 args->Set(1, new base::StringValue("world")); 31 scoped_refptr<Action> action(new Action(kExtensionId, 32 base::Time::Now(), 33 Action::ACTION_API_CALL, 34 kApiCall)); 35 action->set_args(args.Pass()); 36 scoped_ptr<ExtensionActivity> result = action->ConvertToExtensionActivity(); 37 ASSERT_EQ(ExtensionActivity::ACTIVITY_TYPE_API_CALL, result->activity_type); 38 ASSERT_EQ(kExtensionId, *(result->extension_id.get())); 39 ASSERT_EQ(kApiCall, *(result->api_call.get())); 40 ASSERT_EQ(kArgs, *(result->args.get())); 41 ASSERT_EQ(NULL, result->activity_id.get()); 42 } 43 44 TEST_F(ActivityLogApiUnitTest, ConvertDomAction) { 45 scoped_ptr<base::ListValue> args(new base::ListValue()); 46 args->Set(0, new base::StringValue("hello")); 47 args->Set(1, new base::StringValue("world")); 48 scoped_refptr<Action> action(new Action(kExtensionId, 49 base::Time::Now(), 50 Action::ACTION_DOM_ACCESS, 51 kApiCall, 52 12345)); 53 action->set_args(args.Pass()); 54 action->set_page_url(GURL("http://www.google.com")); 55 action->set_page_title("Title"); 56 action->mutable_other()->SetInteger(activity_log_constants::kActionDomVerb, 57 DomActionType::INSERTED); 58 action->mutable_other()->SetBoolean(activity_log_constants::kActionPrerender, 59 false); 60 scoped_ptr<ExtensionActivity> result = action->ConvertToExtensionActivity(); 61 ASSERT_EQ(kExtensionId, *(result->extension_id.get())); 62 ASSERT_EQ("http://www.google.com/", *(result->page_url.get())); 63 ASSERT_EQ("Title", *(result->page_title.get())); 64 ASSERT_EQ(kApiCall, *(result->api_call.get())); 65 ASSERT_EQ(kArgs, *(result->args.get())); 66 scoped_ptr<ExtensionActivity::Other> other(result->other.Pass()); 67 ASSERT_EQ(ExtensionActivity::Other::DOM_VERB_INSERTED, other->dom_verb); 68 ASSERT_TRUE(other->prerender.get()); 69 ASSERT_EQ("12345", *(result->activity_id.get())); 70 } 71 72 } // namespace extensions 73