1#!/usr/bin/env python 2# Copyright (c) 2012 The Chromium Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6'''Unit tests for grit.shortcuts 7''' 8 9import os 10import sys 11if __name__ == '__main__': 12 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) 13 14import unittest 15import StringIO 16 17from grit import shortcuts 18from grit import clique 19from grit import tclib 20from grit.gather import rc 21 22class ShortcutsUnittest(unittest.TestCase): 23 24 def setUp(self): 25 self.uq = clique.UberClique() 26 27 def testFunctionality(self): 28 c = self.uq.MakeClique(tclib.Message(text="Hello &there")) 29 c.AddToShortcutGroup('group_name') 30 c = self.uq.MakeClique(tclib.Message(text="Howdie &there partner")) 31 c.AddToShortcutGroup('group_name') 32 33 warnings = shortcuts.GenerateDuplicateShortcutsWarnings(self.uq, 'PROJECT') 34 self.failUnless(warnings) 35 36 def testAmpersandEscaping(self): 37 c = self.uq.MakeClique(tclib.Message(text="Hello &there")) 38 c.AddToShortcutGroup('group_name') 39 c = self.uq.MakeClique(tclib.Message(text="S&&T are the &letters S and T")) 40 c.AddToShortcutGroup('group_name') 41 42 warnings = shortcuts.GenerateDuplicateShortcutsWarnings(self.uq, 'PROJECT') 43 self.failUnless(len(warnings) == 0) 44 45 def testDialog(self): 46 dlg = rc.Dialog(StringIO.StringIO('''\ 47IDD_SIDEBAR_RSS_PANEL_PROPPAGE DIALOGEX 0, 0, 239, 221 48STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD 49FONT 8, "MS Shell Dlg", 400, 0, 0x1 50BEGIN 51 PUSHBUTTON "Add &URL",IDC_SIDEBAR_RSS_ADD_URL,182,53,57,14 52 EDITTEXT IDC_SIDEBAR_RSS_NEW_URL,0,53,178,15,ES_AUTOHSCROLL 53 PUSHBUTTON "&Remove",IDC_SIDEBAR_RSS_REMOVE,183,200,56,14 54 PUSHBUTTON "&Edit",IDC_SIDEBAR_RSS_EDIT,123,200,56,14 55 CONTROL "&Automatically add commonly viewed clips", 56 IDC_SIDEBAR_RSS_AUTO_ADD,"Button",BS_AUTOCHECKBOX | 57 BS_MULTILINE | WS_TABSTOP,0,200,120,17 58 PUSHBUTTON "",IDC_SIDEBAR_RSS_HIDDEN,179,208,6,6,NOT WS_VISIBLE 59 LTEXT "You can display clips from blogs, news sites, and other online sources.", 60 IDC_STATIC,0,0,239,10 61 LISTBOX IDC_SIDEBAR_DISPLAYED_FEED_LIST,0,69,239,127,LBS_SORT | 62 LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | 63 LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_HSCROLL | 64 WS_TABSTOP 65 LTEXT "Add a clip from a recently viewed website by clicking Add Recent Clips.", 66 IDC_STATIC,0,13,141,19 67 LTEXT "Or, if you know a site supports RSS or Atom, you can enter the RSS or Atom URL below and add it to your list of Web Clips.", 68 IDC_STATIC,0,33,239,18 69 PUSHBUTTON "Add Recent &Clips (10)...", 70 IDC_SIDEBAR_RSS_ADD_RECENT_CLIPS,146,14,93,14 71END'''), 'IDD_SIDEBAR_RSS_PANEL_PROPPAGE') 72 dlg.SetUberClique(self.uq) 73 dlg.Parse() 74 75 warnings = shortcuts.GenerateDuplicateShortcutsWarnings(self.uq, 'PROJECT') 76 self.failUnless(len(warnings) == 0) 77 78if __name__ == '__main__': 79 unittest.main() 80 81