|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include <QtTest/QtTest> |
|
18 #include <w32std.h> |
|
19 #include <s32mem.h> |
|
20 #include <apgtask.h> |
|
21 #include <qdesktopwidget.h> |
|
22 #include <qsignalspy.h> |
|
23 #include <coecntrl.h> |
|
24 |
|
25 #include "t_screenshotplugin.h" |
|
26 #include "tstaskmonitorglobals.h" |
|
27 #include "tsscreenshotmsg.h" |
|
28 |
|
29 |
|
30 const int testTimeout(10000); |
|
31 const int homescreenUID(0x20022F35); |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 class CScreenshotPluginClient: public CWsGraphic |
|
37 { |
|
38 public: |
|
39 static CScreenshotPluginClient* NewLC(MScreenshotObserver& observer) |
|
40 { |
|
41 CScreenshotPluginClient* self = new (ELeave)CScreenshotPluginClient(observer); |
|
42 CleanupStack::PushL(self); |
|
43 self->BaseConstructL(TUid::Uid(0x200267AE), KNullDesC8); |
|
44 return self; |
|
45 } |
|
46 |
|
47 private: |
|
48 CScreenshotPluginClient(MScreenshotObserver& observer) |
|
49 :mObserver(observer) |
|
50 {} |
|
51 |
|
52 void HandleMessage(const TDesC8& data) |
|
53 {TRAP_IGNORE(HandleMessageL(data));} |
|
54 |
|
55 void HandleMessageL(const TDesC8& data) |
|
56 { |
|
57 RDesReadStream msgStream(data); |
|
58 CleanupClosePushL(msgStream); |
|
59 if(RegisterScreenshotMessage != msgStream.ReadInt32L()) { |
|
60 User::Leave(KErrNotSupported); |
|
61 } |
|
62 |
|
63 //parse msg to ACK provider ASAP and be sure that bitmap still exists |
|
64 CTsScreenshotMsg* screenshotMsg = CTsScreenshotMsg::NewLC(msgStream); |
|
65 SendMessage(data); |
|
66 |
|
67 //reset stream |
|
68 msgStream.Close(); |
|
69 msgStream.Open(data); |
|
70 |
|
71 //forward stream to storage |
|
72 mObserver.ScreenshotTaken(screenshotMsg->windowGroupId(), |
|
73 screenshotMsg->screenshot().Handle(), |
|
74 0, |
|
75 screenshotMsg->priority()); |
|
76 |
|
77 CleanupStack::PopAndDestroy(screenshotMsg); |
|
78 CleanupStack::PopAndDestroy(&msgStream); |
|
79 } |
|
80 |
|
81 void OnReplace() |
|
82 {} |
|
83 |
|
84 private: |
|
85 MScreenshotObserver &mObserver; |
|
86 }; |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 |
|
93 T_Screenshotplugin::T_Screenshotplugin() : testUi("test") |
|
94 { |
|
95 testUi.show(); |
|
96 } |
|
97 |
|
98 void T_Screenshotplugin::testPlugin() |
|
99 { |
|
100 const bool appMovingOperations [] = {false, true, false}; |
|
101 QEventLoop loop; |
|
102 connect(this, |
|
103 SIGNAL(screenshotTaken(int, int, int, int)), |
|
104 &loop, |
|
105 SLOT(quit())); |
|
106 |
|
107 CScreenshotPluginClient::NewLC(*this);//create plugin client. test doesnt need pointer |
|
108 |
|
109 //just move tested app to foreground |
|
110 QTimer::singleShot(testTimeout, &loop, SLOT(quit())); |
|
111 moveApp(homescreenUID, true); |
|
112 loop.exec(); |
|
113 |
|
114 //!!!!Tested application should be in foreground!!!!!! |
|
115 //Move tested app foreground/background and wait for screenshot/timeout |
|
116 for (int iter(0), count(sizeof(appMovingOperations)/sizeof(bool)); iter < count; ++iter) { |
|
117 QSignalSpy spy(this, SIGNAL(screenshotTaken(int, int, int, int))); |
|
118 QTimer::singleShot(testTimeout, &loop, SLOT(quit())); |
|
119 moveApp(homescreenUID, appMovingOperations[iter]); |
|
120 loop.exec(); |
|
121 QTest::qWait(4000); |
|
122 QCOMPARE(spy.count(), 1); |
|
123 |
|
124 } |
|
125 //!!!!Tested application should be in background!!!!!! |
|
126 QSignalSpy spy(this, SIGNAL(screenshotTaken(int, int, int, int))); |
|
127 QTimer::singleShot(testTimeout, &loop, SLOT(quit())); |
|
128 moveApp(homescreenUID, false); |
|
129 loop.exec(); |
|
130 QCOMPARE(spy.count(), 0); |
|
131 |
|
132 CleanupStack::PopAndDestroy();//destroy client |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 void T_Screenshotplugin::ScreenshotTaken(int a, int b, int c, int d) |
|
140 { |
|
141 emit screenshotTaken(a, b, c, d); |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 void T_Screenshotplugin::moveApp(int uid, bool foreground) |
|
149 { |
|
150 TApaTaskList taskList(QApplication::desktop()->winId()->ControlEnv()->WsSession()); |
|
151 TApaTask task(taskList.FindApp(TUid::Uid(uid))); |
|
152 if ( task.Exists() ) |
|
153 { |
|
154 foreground ? task.BringToForeground() : task.SendToBackground(); |
|
155 } |
|
156 } |
|
157 |
|
158 QTEST_MAIN(T_Screenshotplugin) |