2012-07-15 16:12:13 -07:00
/ * T h i s S o u r c e C o d e F o r m i s s u b j e c t t o t h e t e r m s o f t h e M o z i l l a P u b l i c
* License , v . 2.0 . If a copy of the MPL was not distributed with this
* file , You can obtain one at http : //mozilla.org/MPL/2.0/. */
function test ( ) {
waitForExplicitFinish ( ) ;
let manifest = { // normal provider
name : "provider 1" ,
2012-09-06 13:14:34 -07:00
origin : "https://example.com" ,
2012-12-08 04:28:54 -08:00
workerURL : "https://example.com/browser/browser/base/content/test/social/social_worker.js" ,
2012-10-09 17:14:25 -07:00
iconURL : "https://example.com/browser/browser/base/content/test/moz.png"
2012-07-15 16:12:13 -07:00
} ;
2012-08-08 18:09:37 -07:00
runSocialTestWithProvider ( manifest , function ( finishcb ) {
runSocialTests ( tests , undefined , undefined , finishcb ) ;
2012-07-15 16:12:13 -07:00
} ) ;
}
var tests = {
testProfileSet : function ( next ) {
let profile = {
2012-08-02 15:30:19 -07:00
portrait : "https://example.com/portrait.jpg" ,
2012-07-15 16:12:13 -07:00
userName : "trickster" ,
displayName : "Kuma Lisa" ,
profileURL : "http://en.wikipedia.org/wiki/Kuma_Lisa"
}
2012-07-18 11:40:05 -07:00
Social . provider . updateUserProfile ( profile ) ;
2012-07-15 16:12:13 -07:00
// check dom values
2012-11-15 15:07:42 -08:00
let portrait = document . getElementsByClassName ( "social-statusarea-user-portrait" ) [ 0 ] . getAttribute ( "src" ) ;
2012-08-02 15:30:19 -07:00
is ( profile . portrait , portrait , "portrait is set" ) ;
2012-11-15 15:07:42 -08:00
let userButton = document . getElementsByClassName ( "social-statusarea-loggedInStatus" ) [ 0 ] ;
2012-07-15 16:12:13 -07:00
ok ( ! userButton . hidden , "username is visible" ) ;
2012-10-09 16:29:13 -07:00
is ( userButton . value , profile . userName , "username is set" ) ;
2012-07-15 16:12:13 -07:00
next ( ) ;
} ,
2012-10-11 18:21:50 -07:00
testNoAmbientNotificationsIsNoKeyboardMenu : function ( next ) {
// The menu bar isn't as easy to instrument on Mac.
if ( navigator . platform . contains ( "Mac" ) ) {
info ( "Skipping checking the menubar on Mac OS" ) ;
next ( ) ;
}
// Test that keyboard accessible menuitem doesn't exist when no ambient icons specified.
let toolsPopup = document . getElementById ( "menu_ToolsPopup" ) ;
toolsPopup . addEventListener ( "popupshown" , function ontoolspopupshownNoAmbient ( ) {
toolsPopup . removeEventListener ( "popupshown" , ontoolspopupshownNoAmbient ) ;
let socialToggleMore = document . getElementById ( "menu_socialAmbientMenu" ) ;
ok ( socialToggleMore , "Keyboard accessible social menu should exist" ) ;
2012-11-26 22:58:55 -08:00
is ( socialToggleMore . querySelectorAll ( "menuitem" ) . length , 6 , "The minimum number of menuitems is two when there are no ambient notifications." ) ;
2012-10-21 17:25:19 -07:00
is ( socialToggleMore . hidden , false , "Menu should be visible since we show some non-ambient notifications in the menu." ) ;
2012-10-11 18:21:50 -07:00
toolsPopup . hidePopup ( ) ;
next ( ) ;
} , false ) ;
document . getElementById ( "menu_ToolsPopup" ) . openPopup ( ) ;
} ,
2012-07-15 16:12:13 -07:00
testAmbientNotifications : function ( next ) {
let ambience = {
name : "testIcon" ,
2012-10-09 17:14:25 -07:00
iconURL : "https://example.com/browser/browser/base/content/test/moz.png" ,
2012-07-15 16:12:13 -07:00
contentPanel : "about:blank" ,
2012-10-11 18:21:50 -07:00
counter : 42 ,
2012-11-28 22:14:48 -08:00
label : "Test Ambient 1 \u2046" ,
2012-10-11 18:21:50 -07:00
menuURL : "https://example.com/testAmbient1"
2012-07-15 16:12:13 -07:00
} ;
2012-11-09 15:36:22 -08:00
let ambience2 = {
name : "testIcon2" ,
iconURL : "https://example.com/browser/browser/base/content/test/moz.png" ,
contentPanel : "about:blank" ,
counter : 0 ,
label : "Test Ambient 2" ,
menuURL : "https://example.com/testAmbient2"
} ;
let ambience3 = {
name : "testIcon3" ,
iconURL : "https://example.com/browser/browser/base/content/test/moz.png" ,
contentPanel : "about:blank" ,
counter : 0 ,
label : "Test Ambient 3" ,
menuURL : "https://example.com/testAmbient3"
} ;
2012-07-18 11:40:05 -07:00
Social . provider . setAmbientNotification ( ambience ) ;
2012-11-28 22:14:48 -08:00
// for Bug 813834. Check preference whether stored data is correct.
is ( JSON . parse ( Services . prefs . getComplexValue ( "social.cached.ambientNotificationIcons" , Ci . nsISupportsString ) . data ) . data . testIcon . label , "Test Ambient 1 \u2046" , "label is stored into preference correctly" ) ;
2012-11-09 15:36:22 -08:00
Social . provider . setAmbientNotification ( ambience2 ) ;
Social . provider . setAmbientNotification ( ambience3 ) ;
2012-07-15 16:12:13 -07:00
2012-09-27 16:57:37 -07:00
let statusIcon = document . querySelector ( "#social-toolbar-item > box" ) ;
waitForCondition ( function ( ) {
statusIcon = document . querySelector ( "#social-toolbar-item > box" ) ;
return ! ! statusIcon ;
} , function ( ) {
let statusIconLabel = statusIcon . querySelector ( "label" ) ;
is ( statusIconLabel . value , "42" , "status value is correct" ) ;
2012-07-15 16:12:13 -07:00
2012-09-27 16:57:37 -07:00
ambience . counter = 0 ;
Social . provider . setAmbientNotification ( ambience ) ;
is ( statusIconLabel . value , "" , "status value is correct" ) ;
2012-10-11 18:21:50 -07:00
// The menu bar isn't as easy to instrument on Mac.
if ( navigator . platform . contains ( "Mac" ) )
next ( ) ;
// Test that keyboard accessible menuitem was added.
let toolsPopup = document . getElementById ( "menu_ToolsPopup" ) ;
toolsPopup . addEventListener ( "popupshown" , function ontoolspopupshownAmbient ( ) {
toolsPopup . removeEventListener ( "popupshown" , ontoolspopupshownAmbient ) ;
let socialToggleMore = document . getElementById ( "menu_socialAmbientMenu" ) ;
ok ( socialToggleMore , "Keyboard accessible social menu should exist" ) ;
2012-11-26 22:58:55 -08:00
is ( socialToggleMore . querySelectorAll ( "menuitem" ) . length , 9 , "The number of menuitems is minimum plus three ambient notification menuitems." ) ;
2012-10-11 18:21:50 -07:00
is ( socialToggleMore . hidden , false , "Menu is visible when ambient notifications have label & menuURL" ) ;
2012-11-15 15:07:42 -08:00
let menuitem = socialToggleMore . querySelector ( ".ambient-menuitem" ) ;
2012-11-28 22:14:48 -08:00
is ( menuitem . getAttribute ( "label" ) , "Test Ambient 1 \u2046" , "Keyboard accessible ambient menuitem should have specified label" ) ;
2012-10-11 18:21:50 -07:00
toolsPopup . hidePopup ( ) ;
next ( ) ;
} , false ) ;
document . getElementById ( "menu_ToolsPopup" ) . openPopup ( ) ;
2012-09-27 16:57:37 -07:00
} , "statusIcon was never found" ) ;
2012-07-15 16:12:13 -07:00
} ,
testProfileUnset : function ( next ) {
2012-07-18 11:40:05 -07:00
Social . provider . updateUserProfile ( { } ) ;
2012-07-15 16:12:13 -07:00
// check dom values
2012-09-27 16:57:37 -07:00
let ambientIcons = document . querySelectorAll ( "#social-toolbar-item > box" ) ;
for ( let ambientIcon of ambientIcons ) {
ok ( ambientIcon . collapsed , "ambient icon (" + ambientIcon . id + ") is collapsed" ) ;
2012-07-15 16:12:13 -07:00
}
2012-10-09 17:14:25 -07:00
next ( ) ;
} ,
2012-11-15 15:07:42 -08:00
testMenuitemsExist : function ( next ) {
let toggleSidebarMenuitems = document . getElementsByClassName ( "social-toggle-sidebar-menuitem" ) ;
is ( toggleSidebarMenuitems . length , 2 , "Toggle Sidebar menuitems exist" ) ;
let toggleDesktopNotificationsMenuitems = document . getElementsByClassName ( "social-toggle-notifications-menuitem" ) ;
is ( toggleDesktopNotificationsMenuitems . length , 2 , "Toggle notifications menuitems exist" ) ;
let toggleSocialMenuitems = document . getElementsByClassName ( "social-toggle-menuitem" ) ;
is ( toggleSocialMenuitems . length , 2 , "Toggle Social menuitems exist" ) ;
let removeSocialMenuitems = document . getElementsByClassName ( "social-remove-menuitem" ) ;
is ( removeSocialMenuitems . length , 2 , "Remove Social menuitems exist" ) ;
2012-07-15 16:12:13 -07:00
next ( ) ;
}
}